delboy1978uk / bone-view
View package for Bone Framework
Installs: 1 774
Dependents: 7
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Language:HTML
Requires
- php: ^8.2
- delboy1978uk/barnacle: ^2.3
- delboy1978uk/bone-http: ^2.4.0
- delboy1978uk/bone-server: ^1.2
- delboy1978uk/icon: ^1.0
- league/plates: ^3.3
- scrutinizer/ocular: ^1.9
Requires (Dev)
- codeception/codeception: ^5.1
- codeception/module-asserts: ^3.0.0
- roave/security-advisories: dev-latest
README
View package for Bone Framework
installation
Bone View is a core dependency of Bone Framework, you install Bone via the skeleton project delboy1978uk/bonemvc
usage
bone-view uses league/plates
as its view engine, see the docs for that. To get an instance of the view engine from
the dependency injection container, call $container->get(ViewEngine::class)
. You can also simply extend Bone\Controller\Controller
and pass through Init::controller($controller)
to get a ViewEngine injected in your class instance.
layouts
Your app by default has layouts in src/App/View/layouts
. You can switch layouts in your controller by adding a
layout
header to your response like so:
return $response->withHeader('layout', 'layouts::your-template');
view extensions
alert box
From a view file, you can call
$this->alertBox($messages);
where messages is an array of variable length, but the last
is the bootstrap alert-*
class, so a value like info
, danger
, warning
, success
, etc.
view helpers
alert box
The view extension just calls this class Bone\View\Helper\AlertBox
, but you can instantiate it and call it yourself.
$alert = new \Bone\View\Helper\AlertBox(); echo $alert->alertBox(['Great success!', 'success']);
Paginator
This should be moved into its own package (imho), however this will render bootstrap compatible paginator nav HTML.
<?php $viewHelper = new \Bone\View\Helper\Paginator(); $viewHelper->setCurrentPage(3); // this number will come from the url $viewHelper->setUrl('/some/page/:number'); // this is the url you are generating $viewHelper->setUrlPart(':number'); // this is the part of the url you will replace with the page number $viewHelper->setPageCount(10); // this is the total number of pages $viewHelper->setPageCountByTotalRecords(50, 10); // Or pass in a row count and num per page to set page count $viewHelper->setPagerSize(5); // this is the number of pages directly clickable in the generated pager $pagination = $viewHelper->render();