icanboogie / bind-view
Binds icanboogie/view to ICanBoogie
Requires
- php: >=8.1
- icanboogie/bind-render: ^6.0
- icanboogie/icanboogie: ^6.0
- icanboogie/view: ^6.0
Requires (Dev)
- phpstan/phpstan: ^1.6
- phpunit/phpunit: ^9.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The icanboogie/bind-view package binds icanboogie/view to ICanBoogie, using its autoconfig feature. It adds getters to controllers and views, making it easy to invoke views from controller actions or get template engines and resolve templates from views, using features of icanboogie/render.
Installation
composer require icanboogie/bind-view
Views and controllers
Views are associated with controllers through the lazy getter view, thus a simple $this->view
is all that is required to enable view features inside a controller. The view then waits for
the Controller::action event to perform its rendering.
The View instance is created with the controller and the Renderer instance obtained from the container.
The following example demonstrates how a query of some articles is set as the view content, a title is also added to the view variables:
<?php use ICanBoogie\Routing\Controller; class ArticlesController extends Controller { use Controller\ResourceTrait; protected function index() { $this->view->content = $this->model->own->visible->ordered->limit(10); $this->view['title'] = "Ten last articles"; } }
Note: The
modelgetter is provided by the icanboogie/module package, and is only available if the route has amoduleproperty, which is automatic for routes defined by modules.
For more information continue to the View documentation.
Continuous Integration
The project is continuously tested by GitHub actions.
Code of Conduct
This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you're expected to uphold this code.
Contributing
See CONTRIBUTING for details.