kadevland / slim-plates-view
此包已被放弃,不再维护。未建议替代包。
基于 Plates 模板组件构建的 Slim Framework 3 视图助手
1.1
2016-10-16 16:33 UTC
Requires
- php: >=5.5.0
- league/plates: ^3.1
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.8.0
This package is not auto-updated.
Last update: 2019-11-06 21:25:46 UTC
README
这是一个基于 Plates 模板组件构建的 Slim Framework 视图助手。您可以使用此组件在 Slim Framework 应用程序中创建和渲染模板。
安装
通过 Composer
$ composer require kadevland/slim-plates-view
需要 Slim Framework 3 和 PHP 5.5.0 或更高版本。
使用方法
// Create Slim app $app = new \Slim\App(); // Fetch DI Container $container = $app->getContainer(); // Register Plates View helper $container['view'] = function ($c) { $view = new \Kadevland\Slim\Plates\View\PlatesView('path/to/templates','extention'); // Instantiate and add Slim specific extension $basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/'); $view->addExtension(new \Kadevland\Slim-Plates-View\PlatesViewExtension($c['router'], $basePath)); return $view; }; // Define named route $app->get('/hello/{name}', function ($request, $response, $args) { return $this->view->render($response, 'profile.html', [ 'name' => $args['name'] ]); })->setName('profile'); // Run app $app->run();
自定义模板函数
此组件向 Plates 模板公开了一个自定义的 path_for()
函数。您可以使用此函数生成指向任何 Slim 应用程序命名路由的完整 URL。这是一个示例 Plates 模板
<h1>User List</h1>
<ul>
<li><a href="<?= $this->path_for('profile', { 'name': 'josh' }) ?>">Josh</a></li>
</ul>
此组件向 Plates 模板提供了一个 is_url()
函数的功能。您可以使用此函数检查 URL 是否与请求 URL/Path 匹配。这是一个示例 Plates 模板
<h1>Categories List</h1>
<ul>
---
$link=path_for('categorie', { 'slug': 'my-categorie' });
<li class="<?=$this->is_url($link)?'active':''?>"><a href="<?=$link?>">My categorie</a></li>
---
</ul>
测试
phpunit
贡献
有关详细信息,请参阅 CONTRIBUTING
许可
MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。