zkwbbr/view
最新稳定版本:v1.2.1
Composer 安装命令:
composer require zkwbbr/view
包简介
Display template file inside a layout file using plain PHP
关键字:
README 文档
README
Display template file inside a layout file using plain PHP
Install
Install via composer as zkwbbr/view
Sample Usage
Create a templates folder (e.g., myTemplates/)
Inside your templates folder, create a layout file (e.g., myLayout.php) and put the ff.
<html> <head> <title><?=$title></title> </head> <body> <?=$templateContent?> </body> </html>
Inside your templates folder, create a view file (e.g., myView.php) and put the ff.
<h1><?=$heading?></h1> <?=$body?>
In your PHP code (e.g., controller), put the ff.
<?php use Zkwbbr\View; $data = [ 'title' => 'My Title', 'heading' => 'My Heading', 'body' => 'My Body' ]; $view = (new View\View) ->setData($data) ->setLayoutFile('myLayout') ->setTemplateVar('templateContent') ->setTemplateDir(__DIR__ . '/myTemplates/') ->setTemplate('myView') ->setBacktraceIndex(0) // # of nested calls relative to render(); for auto-detecting template file (try 0 first then increment until you find it) ->setStripStringFromTemplateFile('foo') // optional, remove string from template file (e.g., if your controller is the basis for auto template detection e.g., UserControllerIndex, and your actual template file is UserIndex, use 'Controller' as value here) ->render(); // you can also use generatedView() to return the generated view instead of outputting it
Expected output
<html> <head> <title>My Title</title> </head> <body> <h1>My Heading</h1> My Body </body> </html>
统计信息
- 总下载量: 144
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-04-02