News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Fabien Potencier's Blog:
Create your own framework... on top of the Symfony2 Components (part 11)
January 24, 2012 @ 11:04:44

In part eleven of his "Build a Framework on top of Symfony2", Fabien Potencier improves on his earlier versions of the code by adding in the HttpKernel support for handling events and errors that might come up in the application.

If you were to use our framework right now, you would probably have to add support for custom error messages. Right now, we have 404 and 500 error support but the responses are hardcoded in the framework itself. Making them customizable is easy enough though: dispatch a new event and listen to it. Doing it right means that the listener has to call a regular controller. But what if the error controller throws an exception? You will end up in an infinite loop. There should be an easier way, right?

Using the "RouterListener" functionality, he sets up an "ExceptionListener" and points that to an error handling controller with its own "exceptionAction". This action takes the exception information and displays a "Something went wrong!" message along with the details. He also includes an update to the Response handling to allow for returning a string back from the controller instead of a Response object.

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


blog comments powered by Disqus

Similar Posts

PHPMaster.com: Proc_Open: Communicate with the Outside World

DZone.com: Sencha Touch 2 Models - Loading And Saving Model Data Using a Proxy, PHP Example

Flyn San: Creating a Basic ToDo Application With Laravel 4 (Tutorial Series)

Developer Tutorials Blog: Getting Started with ORM in PHP

BillS' IIS Blog: How to install FastCGI and PHP on IIS7 Beta 3 (Video)


Community Events





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


deployment interview install library voicesoftheelephpant opinion laravel introduction language package zendserver series unittest bugfix release framework symfony community api podcast

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