The definitive guide of Symfony 1.0

9.5. Dealing with Routes in Actions

If you need to retrieve information about the current route--for instance, to prepare a future "back to page xxx" link--you should use the methods of the sfRouting object. The URIs returned by the getCurrentInternalUri() method can be used in a call to a link_to() helper, as shown in Listing 9-25.

Listing 9-25 - Using sfRouting to Get Information About the Current Route

// If you require a URL like
http://myapp.example.com/article/21

// Use the following in article/read action
$uri = sfRouting::getInstance()->getCurrentInternalUri();
 => article/read?id=21

$uri = sfRouting::getInstance()->getCurrentInternalUri(true);
 => @article_by_id?id=21

$rule = sfRouting::getInstance()->getCurrentRouteName();
 => article_by_id

// If you just need the current module/action names,
// remember that they are actual request parameters
$module = $this->getRequestParameter('module');
$action = $this->getRequestParameter('action');

If you need to transform an internal URI into an external URL in an action — just as url_for() does in a template — use the genUrl() method of the sfController object, as shown in Listing 9-26.

Listing 9-26 - Using sfController to Transform an Internal URI

$uri = 'article/read?id=21';

$url = $this->getController()->genUrl($uri);
 => /article/21

$url = $this->getController()->genUrl($uri, true);
=> http://myapp.example.com/article/21