Download the PHP package markorstc/laminas-typedview without Composer
On this page you can find all versions of the php package markorstc/laminas-typedview. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laminas-typedview
Typed View Layer for Laminas
Key features
- strongly typed view layer
- clean template scope
- easy code navigation
- type hinting
Installation
Install module via Composer
Requirements
PHP 8 or above
Enable module via config
Getting started
Create view model and template
You create a typed view model by extending abstract class TypedView\Entity\ViewModel
. Then you specify path to your .phtml
template file in TypedView\Entity\ViewModel::getTemplate()
method.
Use model in controller
To render your model, simply return it in Laminas controller action as you do it with standard Laminas\View\Model\ViewModel
.
If you want to use common layout for multiple controllers or actions, you have to implement TypedView\Controller\LayoutModelAware
interface in your controller.
At the same time, you specify callback, that will set rendered child model to the parent model (in this case rendered MyListViewModel
to parent MyLayoutModel
).
Use Laminas view helpers
It's possible to use Laminas standard view helpers, but you have to extend TypedView\Entity\LaminasBridgeModel
when creating your typed view model.
If you want to use single particular Laminas view helper and keep clean scope in your template, you can use helper traits e.g. TypedView\Helper\UrlViewHelper
.
Nesting view models
It's possible to use view models as individual components and combine them.
To add one model to another use TypedView\Entity\ViewModel::addChild()
method and specify capture callback the same way like in the layout model example.