2012年10月3日星期三

Dave Marshall: Silex Controllers as Services


Dave Marshall has written up a post about how he uses Silex controllers as services that allow him to define his controller methods in separate classes with a custom resolver.



There's currently a pull request in the queue for Silex that adds a cookbook entry for using controller classes, but I wanted to take it a step further and have my controllers as services, much like what's possible with the full symfony framework (See Richard Miller's post for further reading).


He includes some example code showing the creation of the Silex application with a service definition, the custom "ControllerResolver" to override the default and a simple controller class ("PostController") that just returns a JSON response. You can find the full example code for it on github.

没有评论:

发表评论