News Feed
Sections




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

Dave Marshall:
Silex Route Helpers for a Cleaner Architecture
November 27, 2012 @ 10:57:16

In a previous post of his Dave Marshall talked about using controllers as "services" in a Silex-based application. In this new post he takes it a step further and shows you how to use route helpers to make working with those controllers even simpler.

Supposing we want to render some HTML, do we want to inject the template engine in to the controller? Should the controller be responsible for knowing how to render the template? I'm not sure, but if I can have it not do it with minimal fuss, I think I'd rather it not. The full stack framework has the @Template annotation, which allows developers to assign a template to a controller and then simply return an array. If they can do it in the full stack framework, we can do it in Silex.

He includes the code for an example of a 404 handling page that uses the "convert" method to configure a route (path to a controller) for the currently matched route. He also shows the creation of a simple "CustomRoute" class and a "TemplateRenderingListener" to make it simpler to customize the handling and output of the request, all injected into the application's DI for later use.

0 comments voice your opinion now!
silex microframework controller route helper architecture tutorial


blog comments powered by Disqus

Similar Posts

Rafael Dohms' Blog: Deploying a Symfony2 and Composer app on PagodaBox

Devshed: A Login System for a PHP Email Application

ZendCasts.com: RESTful Delete with SLIM, jQuery and JSON

Zend Developer Zone: 2 Beginners Guides I Wish I had when I Started with PHP

PHPHacks.com: Shell Scripting with PHP CLI


Community Events





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


interview laravel framework api introduction symfony podcast conference voicesoftheelephpant deployment release community list language zendserver code series tips bugfix threedevsandamaybe

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