manychois / views
一个简单的PHP模板库
2.1.0
2023-06-18 06:46 UTC
Requires
- php: >=8
Requires (Dev)
- php: >=8
- escapestudios/symfony2-coding-standard: ^3.13
- phpstan/phpstan: >=1
- phpunit/phpunit: >=10
- slevomat/coding-standard: >=8
- squizlabs/php_codesniffer: >=3
README
一个简单的PHP模板库。版本2是完全重写的。
如何使用
扩展Manychois\Views\AbstractView并在body()函数中定义你的模板。使用$this->inner()或$this->region()来设置你希望注入子内容的区域。对于子模板,覆盖getParentViewClass()来告知此库其父类名称。
然后你可以使用AbstractView::render($templateClassName, $viewData)来进行渲染。
tests/文件夹包含了一些关于AbstractView的示例用法。
实用工具
有几个类可以帮助你生成HTML。
Manychois\Views\Esc
它包含5个方法来在不同的上下文中转义字符串。
attr(string $text, bool $unquoted = false)css(string $text)html(string $text)js(string $text, bool $templateMode = false)url(string $text)
Manychois\Views\ResourceLibrary
它用于管理样式表/脚本依赖。
<?php $r = new \Manychois\Views\ResourceLibrary(); $r->push('a', '<link rel="stylesheet" type="text/css" href="a.css" />', ['b']); $r->push('b', '<link rel="stylesheet" type="text/css" href="b.css" />'); $result = $r->pull('a');
上述$result将包含这个数组数据
[
'b' => '<link rel="stylesheet" type="text/css" href="b.css" />',
'a' => '<link rel="stylesheet" type="text/css" href="a.css" />'
]