brbunny / brplates
BrPlates是一个用于使用Plates处理视图层的组件
Requires
- php: ^7.2|^8.0
- league/plates: 3.*
- matthiasmullie/minify: 1.*
README
BrPlates是一个用于使用Plates处理视图层的组件
安装
BrPlates可以通过Composer获取
"brbunny/brplates": "1.2.*"
或者运行
composer require brbunny/brplates
文档
有关如何使用BrPlates的更多详细信息,请参阅组件目录中的示例文件夹,或访问PlatesPHP了解更多信息。
初始化
要开始使用BrPlates,请在其控制器内部实例化类。了解更多信息,请访问PlatesPHP
Para começar a usar o BrPlates, instancie a classe dentro do seu controlador. Para saber mais, visite PlatesPHP
<?php use BrBunny\BrPlates\BrPlates; class Controller { /** @var BrPlates; */ private $view; public function __construct($path, $ext) { // $this->view = new BrPlates($path, $ext); $this->view = new BrPlates($path); //Extension is optional } }
函数
为特定用途创建一个独特的函数。
Criar uma função única para um caso específico.
<?php // Register a one-off function $this->view->function("name", function ($params) { // Type Code });
path和removePath
将您的模型分组在不同的命名空间中。
Agrupe seus modelos em diferentes namespaces.
<?php // Get template from another directory $this->view->path("profile", "./theme/profile"); //Use template $this->view->show("profile::profile", ["user" => "Jow User"]); // Remove template added $this->view->removePath("profile");
data
如果您在多个模型中具有共同数据,请使用data()
函数。
Se possuir dados em comum em vários modelos utilize a função data()
.
<?php // $this->view->data(['company' => 'BrPlates'], ["_theme", "home"]); $this->view->data(['company' => 'BrPlates']); // Template is Optional
render
如果您想将模型存储在变量中,请使用render()
函数。如果您想直接渲染模型,请使用show()
函数。
Se deseja armazenar o modelo em uma variável, utilize a função render()
. Já se quiser renderizar o modelo direto utilize a função show()
.
<?php $template = $view->render("_theme", ["user" => "Jow User"]); echo $template; $this->view->show("_theme", ["user" => "Jow User"]);
isset
要检查模型是否存在,请简单地使用isset()
函数。
Para verificar se um modelo existe, basta utilizar a função isset()
<?php if ($this->view->isset("_theme")) { // Exist }
widget
如果您想创建组件树,请使用widget()
。
Se você deseja criar uma árvore de componentes, utilize widget()
/* Content of the widgets::list template: <ul> <?= $this->section('widgets') ?> </ul> */ <?= $this->widget("widgets::list", [/* Items */]) ?> // Example <?= $this->widget("widgets::list", [ $this->child("widgets::item", ["content" => "Text"]), $this->child("widgets::item", ["content" => "Text2"]), $this->children("widgets::list2", [ $this->child("widgets::item", ["content" => "Text3.1"]), ], ["label" => "Text3"]) ]) ?>
children
如果您有一个具有子组件的组件,并且该组件包含data
,请使用children()
。
Se existe um componente que possui componentes filhos, e esse mesmo componente contem data
utilize children()
/* Content of the widgets::children template: <li> <?= $label ?> <ul> <?= $this->section('widgets') ?> </ul> </li> */ $this->children("widgets::list2", [ $this->child("widgets::item", ["content" => "Text1.1"]), ], ["label" => "Text1"]);
child
如果组件没有子组件,请使用child()
。
Se o componente não tiver filhos, utilize child()
/* Content of the widgets::item template: <li><?= $content ?></li> */ $this->child("widgets::item", ["content" => "Text"]);
renderMinify
减少渲染代码。
Reduzir código para renderização.
<?php echo $view->renderMinify("profile::profile", ["user" => "Jow User"]);
OBS: 要压缩js脚本,请将"js-mix"放在script标签的起始处
OBS: Para minimizar scripts js, coloque "js-mix" na abertura da tag script
<script js-mix> // Alert alert('minify'); </script> // Result <script>alert('minify');</script>
致谢
- Kevin S. Siqueira(此库的开发者)
- PlatesPHP(文档)
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。