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

Abdul Malik Ikhsan:
Start Using Middleware Approach with new zend-mvc
Mar 02, 2016 @ 18:54:37

Abdul Malik Ikhsan has a post to his site showing how you can integrate the concept of middleware in to the Zend MVC Component of the Zend Framework. Middleware has come into its own with the acceptance of of the PSR-7 standard and several frameworks adopting its structure for request/response handling.

zend-mvc 2.7.0 is coming, beside of the forward compatibility with V3 components, there is new middleware listener that allow us to do Dispatching PSR-7 middleware. The middleware can be an invokable class with __invoke() method.

He shows how, starting with a new project, to create the middleware class (in this case HomeAction) and the __invoke function. He then adds in the "home" route to the module configuration and points it at this HomeAction class. He registers it in the service manager as an InvokableFactory and it magically works. From there he refactors to allow the middleware to work with the ViewModel and change things like templates and variable values.

tagged: middlware zendframework zendmvc component psr7 tutorial invoke

Link: https://samsonasik.wordpress.com/2016/03/01/start-using-middleware-approach-with-new-zend-mvc/


Trending Topics: