![]() |
|
Snippets |
|
You want to get the module, action and parameters associated to a given url, pretty much as the routing system does.
First you will have to remove the part of the url which is not symfony specific. That part typically looks like yoursite.com/path/to/symfony. Once you've done that execute the following code:
$r = new sfRouting(); $r->setRoutes(sfRouting::getInstance()->getRoutes()); $params = $r->parse($myUrl); $module = $params['module']; $action = $params['action'];
Now the module and action associated to this url are as above in $module and $action and the parameters are the remaining elements of the array $params.
Here is how you can get public path to i.e. http://www.domain.com/flash/charts/chart.swf
Put this code into your template.
<?php echo image_path('/flash/charts/chart.swf', true); ?>
Tnx Matt. This is the function I was looking for :)
Here is a usefull helper to calculate url for another application :
function baseurl_for($application, $absolute = false) { $url = $absolute ? 'http://' . $_SERVER["HTTP_HOST"] : ''; $url .= '/' . $application . (SF_ENVIRONMENT != 'prod' ? '_' . SF_ENVIRONMENT : '') . '.php/'; return $url; }
in the action :
<?php echo link_to('Whatever', baseurl_for('application', true) . 'module/action') ?>
I really feel like this feature is missing, hope this could added soon ;) ... example corrected (but sadly not so usefull) according to francois's comment.