simplydi/civiews 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-05