Contents
Laminas
The successor of Zend Framework: modules, the service manager, forms and database access for enterprise projects.
1.Getting started
- Meet LaminasWhat Laminas is, where it came from, which packages it consists of and how a request travels through it.
- InstallationHow to create a Laminas project from the ready-made skeleton, answer the installer's questions and open the first page.
- Project structureWhich folders and files a Laminas project has, what each one holds and which file starts request handling.
- ModulesWhat a Laminas module is and how to create the Blog module by hand: the Module class, the config file, class loading and enabling.
- Configuration and environmentsWhere Laminas configuration lives, how global.php and local.php are merged into one array and what development mode changes.
2.Pages
- RoutingHow to connect a page address to a controller: the router section of the module config, Literal and Segment routes, parameters and constraints.
- Child routesHow to organise the routes of one section into a tree: child_routes, may_terminate and compound route names.
- Controllers and actionsHow to create a Laminas controller, where it lives, how to name an action and why the controller must be registered in the config.
- View scriptsWhere Laminas view scripts live, how the phtml file is found from the action name, how to pass data through a ViewModel and output it safely.
- LayoutWhat a layout is in Laminas, where layout.phtml lives, how a page gets into it and how to change or disable the layout for one action.
- View helpersBuilt-in Laminas view helpers: url for links, basePath for files from public and partial for repeated pieces of markup.
- Request dataHow to read route parameters, the query string and form data in a Laminas controller: the params plugin and the request object.
- ResponseWhat a Laminas action can return besides a page: a redirect, a 404 error, a custom status code and JSON data.
3.Services and the database
- The service managerWhat a service and a factory are in Laminas, how to register a service in the service_manager section and pass it to a controller through the constructor.
- Automatic factoriesHow to avoid writing a factory for every class: ReflectionBasedAbstractFactory and ConfigAbstractFactory in Laminas and when to choose which.
- Database connectionHow to install laminas-db, put the connection parameters into the configuration, create the posts table and run the first query.
- TableGateway and a model classHow to read and save table rows in Laminas: the Post row class, the TableGateway, the PostTable class with its factory and the call from a controller.
- The Sql query builderHow to build queries in Laminas without gluing strings: the Select object, where conditions, ordering, joins, counting and transactions.
4.Forms and users
- FormsHow to describe a Laminas form as a class, render it with view helpers and handle the submitted data in a controller.
- ValidationHow to add rules to a Laminas form: filters and validators in getInputFilterSpecification, custom error messages and validating data without a form.
- SessionsHow to keep a visitor's data between requests in Laminas: the laminas-session package, the Container object, session settings and Csrf token protection for forms.
- Flash messagesHow to show the visitor a message after a redirect: the flashMessenger plugin in a controller and rendering messages in the Laminas layout.
- File uploadsHow to add a file field to a Laminas form, check the size and extension, store the file in public/uploads and show it on the page.
- User loginAuthentication in Laminas: the laminas-authentication package, a custom adapter that checks the password, the AuthenticationService, login, logout and the current user.
- Access controlHow to close Laminas pages to guests with a route event listener and how to describe roles and permissions with laminas-permissions-acl.
5.Growing the project
- EventsHow request handling works in Laminas: MvcEvent events, listeners in Module::onBootstrap, priorities and custom service events.
- Controller pluginsWhat a controller plugin is in Laminas, how to write your own, register it in controller_plugins and call it in an action.
- Custom view helpersHow to write your own Laminas view helper, register it in the view_helpers section and call it in phtml files.
- PaginationHow to split the list of posts into pages in Laminas: the laminas-paginator package, the adapter for a database query and rendering links with paginationControl.
- REST APIHow to serve blog data as JSON: the AbstractRestfulController, its methods, the API route and checking requests with curl.
- Console commandsHow to write your own console command for a Laminas application with the laminas-cli package: the command class, registration in the config and running it.
- CachingHow to store the results of slow operations in Laminas: the laminas-cache package, the caches config section and the getItem, setItem, removeItem methods.
- LoggingHow to write application events and errors of a Laminas application to a file: a PSR-3 logger with Monolog, a factory, message levels and logging exceptions.
- TestingHow to check the pages of a Laminas application automatically: the laminas-test package, the AbstractHttpControllerTestCase class, response assertions and replacing services.
- DeploymentHow to prepare a Laminas application for a server: production mode, the configuration cache, web server setup and the update routine.