![]() |
|
Snippets |
|
Here is a forward method wrapper that accepts a routing label. Since forward does not do parameters neither does this. Though it would be nice.
public static function fooForward(&$sfa, $route) { $url = sfContext::getInstance()->getController()->genUrl($route); $routing = explode("/", $url, 3); switch (count($routing)) { case (3): $sfa->forward($routing[1],$routing[2]); break; case (2): $sfa->forward($routing[1], 'index'); break; default: error_log(sprintf("Error in fooForward for routing label %s", $route)); break; } }
Call it in an action:
public function handleError() { fooTools::fooForward($this, '@someLabel'); }
If there where parameters in the label the $url would have them. Though they can not be used in this case.
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.