Skip to content

Load the Url symfony helper in a model or form class

I'm doing some symfony work and needed to use the Url helper in a form class to return an error message that included a link. I would consider this one of those exceptions where you really need to be able to have markup in a class rather than in a template.

I should probably mention that this is the way that works in version 1.4.3, and that the method that works in actions will not work in a form class. That method is:


sfContext::getInstance()->getConfiguration()->loadHelpers(...);
 


That method was deprecated and there is also this article to consider.

In this case, the solution was to access the sfApplicationConfiguration object. In order to use the Url helper so you can call link_to() you need to also include the 'Tag' helper.


sfApplicationConfiguration::getActive()->loadHelpers(array('Url', 'Tag'));

// now you can use link_to(...)
 


Obviously this would allow you to load other helpers in the same way ... i18n for example.