jsangrador/phptal-view

此包已被废弃且不再维护。未建议替代包。

将 PHPTAL 视图模板渲染成 PSR-7 响应对象。

3.0.0 2016-01-21 23:14 UTC

This package is not auto-updated.

Last update: 2020-10-21 00:58:41 UTC


README

此分支的开发已迁移至 https://gitlab.com/jsangradorp/PHPTAL-View

PHPTAL 渲染器

这是一个将 PHPTAL 视图脚本渲染成 PSR-7 响应对象的渲染器。它与 Slim 框架 3 配合良好。

安装

使用 Composer 安装

composer require jsangrador/PHPTAL-view

与 Slim 3 的使用

use Slim\Views\PhpTalRenderer;

include "vendor/autoload.php";

$app = new Slim\App();
$container = $app->getContainer();
$container['renderer'] = new PhpTalRenderer("./templates");

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->renderer->render($response, "/hello.html", $args);
});

$app->run();

与任何 PSR-7 项目的使用

//Construct the View
$phpView = new PhpTalRenderer("./path/to/templates");

//Render a Template
$response = $phpView->render(new Response(), "/path/to/template.html", $yourData);

异常

\RuntimeException - 如果模板不存在

\InvalidArgumentException - 如果 $data 包含 'template'