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.


November 30, 2006
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.


December 1, 2006
gravatar denderello: Thanks skoop! You saved my day!
May 4, 2009
gravatar left: Hi denderello,

Old though this post may be, good that it is still of use :)

Stefan
May 4, 2009
gravatar pepe18: sfLoader no longer exists, use this:
sfApplicationConfiguration::getActive()->loadHelpers(array('Url'));
February 26, 2011
gravatar what causes pneumonia: Stefan, can you please drop me an email regarding Metal Machine Music Live/ Thanks.

February 9, 2012
gravatar Time Warner Packages: Nice posting... I like it! Thanks for sharing. Keep on posting…
February 24, 2012
gravatar tilting patio umbrella: I'm still learning from you, however I'm improving myself. I definitely love studying every little thing that is written on your blog.Preserve the stories coming. I cherished it!
March 8, 2012
gravatar LED spotlight: You also know how to make people rally behind it, obviously from the responses. :lol:
March 14, 2012
gravatar debt consolidation: Symfony is aimed at building robust applications in an enterprise context, and aims to give developers full control over the configuration: from the directory structure to the foreign libraries, almost everything can be customized. To match enterprise development guidelines, Symfony is bundled with additional tools to help developers test, debug and document projects. Thanks.
March 21, 2012

Php5_zce_logo

Upcoming events

I will be speaking 05-06-2012: Forum PHP
I will be attending 06-06-2012: Symfony Live Paris 2012
I will be attending 07-06-2012: Symfony Live Paris 2012
I will be attending 08-06-2012: Symfony Live Paris 2012
I will be attending 09-06-2012: Symfony Live Paris 2012
I will be attending 23-06-2012: PHP TestFest NL

Tags

1337 2008 2010 2011 4developers access modifiers accessibility AdaLovelaceDay09 advent agavi agile alfred amsterdam apache api apple article articles atk atkMetaNode audioscrobbler autoloading automation azure backwards compatibility barcelona barcodes bash bbc bbq beatstad belgium best practices bittorrent blogging blogs boards of canada book books bughuntday bundle caching cake cal evans calendar career cat cerf certificate cfp cilex clear cms cologne common sense communities community components composer conference conferences contest continuous integration contribute contribution crisis css curl custom d-day datetime DbFinderPlugin decorator decorators deployment deps devdays development directoryindex directoryiterator docblox doctrine documentation download dpc dpc09 dpc10 dpc11 DPC2008 dreamhost drupal dv7 eclipse ed editors efficiency enterprise errors event events expertise ezcomponents facebook filter-branch filteriterator finland flickr fork framework frameworks freelance freeze frontend fun game games geoip germany getting real git github globiterator gnome-do google google calendar googletalk graceful degradation hack hackers hidden gem hiphop howto hp HR html http i386 ibuildings icann ide ideasofmarch idm imovie inclusivity indy ingewikkeld integration international php conference internet interview ipad IPC ipc ipc08 ipc10 ipc11se iterators iterm2 javascript jenkins jenkins-php job job openings jobeet john peel joomla joomladays kiva kubuntu launcher launchy left on the web libcurl libraries library lighttpd lime linktuesday linux live london loudblog m2ts mac magazines malware mambo marjolein mediterra meeting meme meta methodology micro-financing microframework microsoft migration movie music mysql namespace namespaces netbeans netherlands newsfire nllgg northeastphp nos odmarco open source opinion ORM osx paradiso paris partnership pavilion pear pecl performance personal pfc10 pfc11 pfcongres pfcongrez pfz photo php PHP php5.3 phpabstract phpazure phpBB phpbb phpbelgium phpbenelux phpbnl10 phpday phpdoc phpdocumentor phpgg phpitalia phpnw phpnw08 phpnw11 phpstorm phptek phptek09 phpuk2009 phpUnderControl phpunit php|architect php|tek podcast politics portability postcrossing presentation presentations private projects protected prototype PSR-0 public python qa qr codes re2c recruiting refactoring review rewrite ruby on rails san francisco schedule scifi script security sensio seven things sfdaycgn sflive2011 shell scripting silex simplexml slides smfony software sogeti solar sound speakers spl ssh standard standards star trek static steer strings stylesheets subversion symfony symfony live Symfony2 symfonycamp symfonyday symfonylive symfonyUnderControlPlugin talk talks tech techademy technology techportal tek09 telecommuting terratec terrorism testfest testing textmate textpattern the right tool timeout tips tld todo tomas tools training twig uncon unet usability usergroup validation vhost video vim vinyl virus warp webinar weblogging webservices wiki windows winphp women wordpress work workshop world world of warcraft wpi writing wunderlist xml xpath xsd yara year youtube zc11 ZCE zemanta zend zend framework zend server zend studio zendcon Zend_Form zite
© 2004 - 2012 Stefan Koopmanschap + Powered by Symfony, photos powered by Flickr, links powered by Delicious, Shanghai smilies by Iconbuffet. Feeds: rss / atom. Left on the Web v4.4.0.1