delboy1978uk / bone-view
查看 Bone 框架的包
v1.8.1
2024-04-17 15:47 UTC
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
查看 Bone 框架的包
安装
Bone View 是 Bone 框架的核心依赖,您可以通过骨架项目 delboy1978uk/bonemvc
安装 Bone。
用法
bone-view 使用 league/plates
作为其视图引擎,请参阅相关文档。要从依赖注入容器中获取视图引擎的实例,请调用 $container->get(ViewEngine::class)
。您也可以简单地扩展 Bone\Controller\Controller
并通过 Init::controller($controller)
将其传递给类实例以获取注入的 ViewEngine。
布局
您的应用程序默认在 src/App/View/layouts
中有布局。您可以在控制器中通过向响应添加一个 layout
标头来切换布局,如下所示
return $response->withHeader('layout', 'layouts::your-template');
视图扩展
警告框
从视图文件中,您可以调用
$this->alertBox($messages);
其中 messages 是一个长度可变的数组,但最后一个值是 bootstrap 的 alert-*
类,所以值可以是 info
、danger
、warning
、success
等。
视图辅助器
警告框
视图扩展仅调用此类 Bone\View\Helper\AlertBox
,但您也可以实例化它并自行调用。
$alert = new \Bone\View\Helper\AlertBox(); echo $alert->alertBox(['Great success!', 'success']);
分页器
我认为这应该移动到自己的包中,但这将渲染与 bootstrap 兼容的分页器导航 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();