slabphp/display

SlabPHP 显示和模板库

v0.1.9 2018-02-20 00:00 UTC

This package is auto-updated.

Last update: 2024-09-22 05:41:43 UTC


README

关于这个库,它使用 "php" 模板文件执行轻量级但有序的输出操作。文件包含在 Template 类的上下文中。就像许多 SlabPHP 一样,这个库是很久以前编写的。它仍然假设你可能在模板中执行业务逻辑,尽管这被认为是一种不好的设计。有关 SlabPHP 的更多信息,请参阅核心库中的文档。你可能想考虑使用更现代的工具,如 mustache 进行模板设计。

关于安全性的说明,php 模板文件应该与其他代码库的部分一样安全。你需要确保你通过谨慎使用正确的文件系统权限和目录路径,没有包含非你编写的模板文件。话虽如此,如果你的代码库被入侵,加载恶意代码的可能性是存在的。然而,如果你的代码库被入侵,这个库可能并不是你最需要担心的问题。

安装和使用

首先包含库

composer require slabphp/display

然后实例化并显示一个模板。

$template = new \Slab\Display\Template();
$template->setTemplateSearchDirectories(['default'=>__DIR__.'/templates']);

$output = $template->renderTemplate('standard.php', ['name'=>'Sam'], true);

只要 ~/templates/standard.php 文件存在,它就会加载它,并且由于第三个参数为 true,它将返回到 $output;假设该文件看起来像这样

Hello there <?php echo $this->name; ?>!

那么 $output 将包含 "Hello there Sam!"