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

Alejandro Celaya:
How to customize "not found" and "method not allowed" response prototypes in Zend
May 31, 2017 @ 15:10:23

Alejandro Celaya has posted a new tutorial on his site showing how you can customized the "not found" and "not allowed" responses in a Zend Expressive v2 application based on the needs of your application.

Sometimes the nature of an application requires you to change the default framework's way to structure error responses (like 404 and 405).

On this article I'm going to explain how to customize those responses when working with Zend Expressive 2. [...] In Expressive 1, error handling was different. [...] In expressive 2, the error handler is gone, replaced by a middleware which catches exceptions and lets you generate error responses.

He notes that this new middleware approach (moving away from the error handler) doesn't deal with 404 and 405 errors anymore, they've been split out into other functionality. As these other middleware options allow for a custom PSR-7 response object to be injected, he sets up two "delegates" that will more correctly handle the response. He includes the examples code for these and shows how to hook them into the current Expressive execution flow.

tagged: zendexpressive tutorial customize notfound methodnotallowed response custom psr7

Link: https://blog.alejandrocelaya.com/2017/05/28/how-to-customize-not-found-and-method-not-allowed-response-prototypes-in-zend-expressive-2/


Trending Topics: