Mezzio is a micro-framework, and primarily provides wiring between a container, routing, templating, and error handling. For everything else, you add it in yourself, generally using Composer.
For database abstraction, you can choose from laminas-db, Doctrine DBAL, or even go full ORM with Doctrine ORM. For pagination, check out laminas-paginator — which provides laminas-db adapters, and for which Doctrine provides adapters. For forms, you can choose from laminas-form, or go a level lower to laminas-inputfilter or marcosh/php-validation-dsl. For authentication and authorization, we have a number of libraries in the Mezzio ecosystem already; see the overview in the documentation landing page.
Generally speaking we recommend creating namespaced “modules” in your application. These live under the
src/ tree, and the skeleton provides one for you out-of-the-box (“App”); you can add more by adding sibling directories with corresponding entries in your
autoload.psr-4 rules. How you structure these is up to you; I generally structure them based on responsibility or context, which can vary a ton between applications.
You will have a few things always:
ConfigProvider to wire your services and any namespace-specific configuration.
- Handlers, which are the endpoints of your application - these do the actual work for any given request, and are ultimately what routes will match to.
- Middleware, if you have any pre-processing you want to do for a request (e.g., validation, authn, authz, etc.) or post-processing of a response (e.g., adding response headers, calculating signatures, etc.)
- I often also define commands, if there are things I might want to do to build something during deployment, or for cronjobs. These will tie into laminas-cli configuration, and extend the symfony/console
For an example, I can point you to my personal website, as the code is public. This application uses mezzio-swoole, so there’s a bit of additional bits and pieces around ensuring certain services are stateless, and to allow dispatching async tasks via Swoole task workers.