node-link / cakephp-smarty
将 Smarty 框架集成到 CakePHP 中。
v0.2.1
2018-09-21 15:05 UTC
Requires
- php: >=5.5
- cakephp/cakephp: ^3.4
- smarty/smarty: ^3.1
Requires (Dev)
- phpunit/phpunit: ^5.7|^6.0
This package is auto-updated.
Last update: 2024-09-28 04:44:26 UTC
README
Smarty 插件是一种简单的方法,通过 3 个步骤将 Smarty 视图集成到您的 CakePHP 3 应用程序中。
需求
- CakePHP 3.x
- PHP 5.5+
安装
1. 安装插件
您可以使用 composer 将此插件安装到 CakePHP 应用程序中。
推荐安装 composer 包的方法是
composer require node-link/cakephp-smarty
2. 加载插件
使用 bin/cake
按以下方式加载插件
bin/cake plugin load NodeLink/Smarty
或者,手动将以下内容添加到 config/bootstrap.php
<?php use Cake\Core\Plugin; Plugin::load('NodeLink/Smarty');
3. 设置视图类
在您的应用程序的 AppController.php
文件中指定视图类。
<?php namespace App\Controller; use Cake\Controller\Controller; use Cake\Event\Event; class AppController extends Controller { public function beforeRender(Event $event) { $this->viewBuilder()->setClassName('NodeLink/Smarty.App'); // Prior to CakePHP 3.4.0 $this->viewBuilder()->className('NodeLink/Smarty.App'); } }
配置
如果您想更改 Smarty 的行为,可以通过以下方式在 config/app.php
中进行更改。
<?php return [ // Add the following 'Smarty' => [ 'debugging' => true, // Default: Configure::read('debug') 'auto_literal' => true, // Default: true 'escape_html' => true, // Default: false 'left_delimiter' => '<!--{', // Default: '{' 'right_delimiter' => '}-->', // Default: '}' 'error_reporting' => E_ALL & ~E_NOTICE, // Default: null 'force_compile' => true, // Default: Configure::read('debug') 'caching' => Smarty::CACHING_LIFETIME_CURRENT, // Default: false 'cache_lifetime' => 86400, // Default: 3600 'compile_check' => true, // Default: true 'compile_dir' => null, // Default: CACHE . 'views' 'cache_dir' => null, // Default: CACHE . 'smarty' 'config_dir' => null, // Default: CONFIG . 'smarty' 'plugins_dir' => null, // Default: CONFIG . 'smarty' . DS . 'plugins' 'template_dir' => null, // Default: APP . 'Template' 'use_sub_dirs' => false, // Default: false ], ];
如果设置项未填写或设置为 null,则使用默认值。
如果您想定义插件,如函数和修饰符,默认情况下 config/smarty/plugins
是插件目录,因此请将插件放在 config/smarty/plugins
目录中。
报告问题
如果您遇到 Smarty 插件的问题,请发送一个 pull request 或在 GitHub 上打开一个 issue。