News Feed
Jobs Feed
Sections




News Archive
Fabien Potencier's Blog:
Create your own framework... on top of the Symfony2 Components (part 6)
January 13, 2012 @ 11:08:12

In the sixth part of his series on creating a custom framework on top of the Symfony2 components, Fabien Potencier looks at how to improve the previous examples by swapping out the more procedural controllers with actual classes.

The move is pretty straightforward and makes a lot of sense as soon as you create more pages but you might have noticed a non-desirable side-effect... The LeapYearController class is always instantiated, even if the requested URL does not match the leap_year route. This is bad for one main reason: performance wise, all controllers for all routes must now be instantiated for every request. It would be better if controllers were lazy-loaded so that only the controller associated with the matched route is instantiated.

To help solve the issue, he uses the HttpKernel component and its "controller resolver" to figure out how to call the controller and pass it the correct parameters, but only when needed. A resolver object is created and that is used to instantiate the controller object. Sample "action" calls are included to fill out the basic controller (his "leap year" example) and the full resulting code is included both for the framework and the new object oriented controller.

0 comments voice your opinion now!
framework symfony2 tutorial series component controller


blog comments powered by Disqus

Similar Posts

CodeIgniterPodcast.com: Ep. #4 - Changes to CodeIgniter 2.0 and the Community Branch

Zend Developer Zone: Zip-it or DIY Tar-balls

Mike Willbanks' Blog: Android C2DM with PHP and Zend Framework

PHPied.com: Getting an RSS feed with the Zend framework 0.1.1

SaniSoft Blog: Lambda functions and Closures in PHP 5.3c


Community Events











Don't see your event here?
Let us know!


interview framework series phpunit introduction database podcast usergroup development release rest testing functional conference unittest language zendframework2 community symfony2 opinion

All content copyright, 2013 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework