Code snippets for symfony 1.x


Refine Tags

Snippets tagged "action routing"

forward wrapper that accepts a routing label

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):
      case (2):
        $sfa->forward($routing[1], 'index');
        error_log(sprintf("Error in fooForward for routing label %s", $route));

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.

by roland cruse on 2006-09-27, tagged action  forward  handleerror  routing 

Get the module, action and parameters from a url

The problem

You want to get the module, action and parameters associated to a given url, pretty much as the routing system does.

The solution

First you will have to remove the part of the url which is not symfony specific. That part typically looks like Once you've done that execute the following code:

$r = new sfRouting();
$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.

by Olivier Verdier on 2006-07-21, tagged action  module  parameters  routing  url