Laminas Best Practices
5 min read Quiz at the end
Laminas best practices: ServiceManager for all deps, escape output, thin controllers, cache.
Laminas / Zend Best Practices
- Use ServiceManager (DI container) for all dependencies — never
new inside methods - Separate configuration per environment using
autoload/ glob pattern - Use InputFilter for validation — never trust raw POST/GET
- Escape ALL output with
$this->escapeHtml() in views - Use ACL or RBAC for authorization
- Keep controllers thin — delegate to model/service layer
- Cache expensive queries with Laminas Cache
- Use Mezzio for new API-only services
- Write unit tests for every model and service
- Use Laminas Session with strict mode enabled