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.


Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

Luis Arizaga on :

*Thanks a lot!!! it really helped me. Greetings from Argentina.

jaffa on :

*Great blog.

Add Comment

Pavatar, Gravatar, Favatar, MyBlogLog, Pavatar author images supported.
BBCode format allowed
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
Form options