Generating url using routing from anywhere in Symfony

Posted on Category:Symfony

This post describes how to generate URL from anywhere in Symfony application. For example, I needed to create URL for forgotten password within an error message for invalid e-mail address. Needless to say, this should be done in user registration form class.

Url can be generated from anywhere in symfony application by using sfContext like in the following example:
[php]
$some_url = sfContext::getInstance()->getRouting()->generate(‘route_name’);
[/php]