How to display a custom error page for HTTP status 405 (method not allowed) and etc?

How Can I customize custom pages template for errors?

By default, we provide Mezzio\Router\Middleware\MethodNotAllowedMiddleware, which you will see piped into the pipeline in your config/pipeline.php file. That middleware creates an empty response that contains just the status code and the appropriate Allow header.

You have two options if you want to provide a template page for it:

  • Create your own MethodNotAllowedMiddleware that renders a template into a 405 response you create yourself, and pipe that as a replacement for the default.
  • Create middleware that you register earlier in the pipeline that only inspects outgoing responses in order to determine if a 405 response is present, and, if so, renders a template into the response body.

Now, for other error types, what you will need is an ErrorResponseGenerator. This is a class defining __invoke() that gets injected into the ErrorHandler middleware in order to create error responses. In such a class, you could pull the status code, and map those to templates. For an example of an error response generator see the Statigility documentation. Internally, we register such generators under the service name Mezzio\Middleware\ErrorResponseGenerator; you would provide an alternate factory to substitute your version instead of the default.

Thank you. I really like mezzio, it is very simple and comfortable for me. But at this time, mezzio has a very little community and a bit composer-packages.

What are your criteria for developing official mezzio packages?
How can my package get to the official mezzio repository?

The first step is to create an RFC in the Contributors section of the forums here. From there, the technical steering committee will evaluate and vote on whether or not it is something we want to bring in and maintain.

Also, you can always create and publish your own packages! In the “keywords” section of your package, include “mezzio”, so that people can find them (I’d also suggest making them work on other PSR-15 platforms, and including the “psr-15” keyword!).