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

Rob Allen:
OuputBuffer Middleware for Expressive
Oct 25, 2017 @ 14:56:14

In a quick post to his site Rob Allen shares code for an OutputBuffer middleware for use with the Zend Expressive framework. Zend Expressive is a middleware-driven framework that makes use of several Zend Framework components to get the job done.

When developing an Expressive application, if you use var_dump(), echo, print_r(), etc when you get [an] error.

This occurs after your data has been displayed and makes perfect sense as Expressive is unable to send headers as you've already started sending the body. To solve this, you need some middleware.

He includes the code for the middleware that grabs the current output being pushed to the user and, using PHP's own output buffering, takes all output and pushes it into the body, preventing any messages about output before the rendering takes place.

tagged: zendexpressive outputbuffer output middleware example

Link: https://akrabat.com/ouputbuffer-middleware-for-expressive/


Trending Topics: