Meet Laminas
Laminas is a set of PHP packages for building websites and the continuation of Zend Framework, one of the best-known frameworks for enterprise projects. In 2020 Zend Framework was handed over to the Linux Foundation and renamed Laminas; the code stayed the same, only the class names changed.
This course describes an application built on laminas-mvc version 3 and PHP 8.1 or newer.
How Laminas differs
Almost nothing in Laminas happens "by itself". The page address, the controller class, the way it is created — everything is written down in configuration files, plain PHP files that return an array. There is more code than in Laravel, but you can always see where things come from.
This is what a fragment of such a file looks like:
// module/Application/config/module.config.php
return [
'view_manager' => [
'doctype' => 'HTML5',
],
];The view_manager key is the section with template settings, and doctype is one setting inside it. You will work with arrays like this in every lesson.
What MVC is
MVC is a way to split code into three parts:
| Part | What it does | Where it lives |
|---|---|---|
| Model | Works with data and the database | module/Blog/src/Model |
| View | Builds the HTML of a page | module/Blog/view |
| Controller | Receives the request and connects the other two | module/Blog/src/Controller |
How a request travels
- The browser requests an address, for example
/blog. - The router finds a route for that address in the configuration.
- The route names a controller and an action — a method of the controller.
- The action prepares data and returns it.
- A view script turns the data into HTML, and the layout adds the common page frame.
Laminas packages
Laminas consists of separate packages. Each one is installed with Composer when you need it:
| Package | Purpose |
|---|---|
laminas-mvc | Routes, controllers, view scripts |
laminas-servicemanager | Creating the application's objects |
laminas-db | Database access |
laminas-form, laminas-inputfilter | Forms and validation |
laminas-authentication | User login |
laminas-eventmanager | Events |
What you will build
Through the course you will build a blog: a list of posts, a post page, a form for adding posts, a login for the author and a small API. Each lesson adds one piece to it.
Common mistake
Old articles and forum answers contain class names that start with Zend\. That code will not work in a new project: replace Zend with Laminas in every name, for example Zend\Mvc\Controller\AbstractActionController becomes Laminas\Mvc\Controller\AbstractActionController.