Left on the Web

Using helpers in actions (Symfony)

We recently had a weird situation here at work where we needed to use the Url helper of Symfony inside the actions.class.php of a module. This helper is available in the view, but not in the actions class by default. The solution is simple, but you need to know it first.

We recently had a weird situation here at work where we needed to use the Url helper of Symfony inside the actions.class.php of a module. This helper is available in the view, but not in the actions class by default. Of course, we can include this, and this was my first approach. Simply using:
include_once('symfony/helper/UrlHelper.php');
worked fine for me. However, when my co-worker updated his code from Subversion, it went BOOM. He got a rather annoying FATAL error about not being able to redeclare a function. It's weird, because it worked in my situation. The solution is simple though, and was available in the Symfony trac. Ticket #899 contains the solution, which is more simple than you could imagine:
sfLoader::loadHelpers(array('Url'));
Simple!
Add comment

Comments

gravatar Ken: How do you find Symfony? Compare to say Zend Framework adn others.


gravatar left: Hi Ken,

In an earlier post (http://www.leftontheweb.com/article/291/symfony-no-cacaphony-of-code) I already went into Symfony a bit. I love it, basically. It takes all the annoying work out of the hands of the developer. Compared to for instance Zend Framework, Symfony is just more mature. I definitely see an interesting future for ZF, but not at this moment. The API is not set in stone yet, too much is being refactored without regard for backwards compatibility. Symfony is nearing 1.0 stable and is actually aiming to release that this year.

So yes, I am very happy with Symfony.


© 2004 - 2009 Stefan Koopmanschap + Powered by Symfony, photos powered by Flickr, links powered by Ma.gnolia, Shanghai smilies by Iconbuffet. Feeds: rss / atom. Left on the Web v4.2.3