simplydi/civiews
Composer 安装命令:
composer require simplydi/civiews
包简介
A Simple, Native PHP Templating Engine decoupled from CodeIgniter 4
README 文档
README
A Simple, Native PHP Templating Engine decoupled from CodeIgniter 4
Usage
Writing Templates: refer to CI4 docs
Example 1:
$data = [ 'title' => 'Dummy Title' ]; $renderer = new \SimiplyDi\CIViews\Renderer('/path/to/templates/dir'); $renderer->data = $data; // or $renderer->setVar('title', $data['title']); echo $renderer->render('home');
Example with DI
MyController.php:
class MyController { private RendererInterface $renderer; public function __construct(RendererInterface $renderer) { $this->renderer = $renderer; } public function index(): string { $this->renderer->data = [ 'title' => 'Welcome to website', 'content' => 'welcome to website', ]; return $this->renderer->render('home'); } }
Dependency Container (use any container you want). Example:
$container = new Container(); $container->bind(RendererInterface::class, function () { // pass the templates directory as first param and extension you want to use (optional; defaults to .php) return new Renderer(__DIR__ . '/views', '.phtml'); }); $container->bind(MyController::class, function () use ($container) { return new MyController($container->resolve(RendererInterface::class)); });
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-05