Yaf整合Smarty模板引擎
来源:互联网 发布:用编程代码说我爱你 编辑:程序博客网 时间:2024/06/05 03:57
将Smarty文件夹放在library目录下面
在Smarty目录下面添加Adapter.php,代码如下:
<?phprequire "Smarty.class.php";class Smarty_Adapter implements Yaf_View_Interface{ /** * Smarty object * @var Smarty */ public $_smarty; /** * Constructor * * @param string $tmplPath * @param array $extraParams * @return void */ public function __construct($tmplPath = null, $extraParams = array()) { $this->_smarty = new Smarty; if (null !== $tmplPath) { $this->setScriptPath($tmplPath); } foreach ($extraParams as $key => $value) { $this->_smarty->$key = $value; } } /** * Return the template engine object * * @return Smarty */ public function getEngine() { return $this->_smarty; } /** * Set the path to the templates * * @param string $path The directory to set as the path. * @return void */ public function setScriptPath($path) { if (is_readable($path)) { $this->_smarty->template_dir = $path; return; } throw new Exception('Invalid path provided'); } /** * Retrieve the current template directory * * @return string */ public function getScriptPath() { return $this->_smarty->template_dir; } /** * Alias for setScriptPath * * @param string $path * @param string $prefix Unused * @return void */ public function setBasePath($path, $prefix = 'Zend_View') { return $this->setScriptPath($path); } /** * Alias for setScriptPath * * @param string $path * @param string $prefix Unused * @return void */ public function addBasePath($path, $prefix = 'Zend_View') { return $this->setScriptPath($path); } /** * Assign a variable to the template * * @param string $key The variable name. * @param mixed $val The variable value. * @return void */ public function __set($key, $val) { $this->_smarty->assign($key, $val); } /** * Allows testing with empty() and isset() to work * * @param string $key * @return boolean */ public function __isset($key) { return (null !== $this->_smarty->get_template_vars($key)); } public function __unset($key) { $this->_smarty->clear_assign($key); } public function assign($spec, $value = null) { if (is_array($spec)) { $this->_smarty->assign($spec); return; } $this->_smarty->assign($spec, $value); } public function clearVars() { $this->_smarty->clear_all_assign(); } public function render($name, $value = NULL) { return $this->_smarty->fetch($name); } public function display($name, $value = NULL) { echo $this->_smarty->fetch($name); }}/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */?>
在application.ini中添加配置。如下:
使用Bootstrap.php文件
在入口文件中:
然后编辑Bootstrap.php文件。如下:
public function _initSmarty(Yaf_Dispatcher $dispatcher){ Yaf_Loader::import("Smarty/Adapter.php"); $smarty = new Smarty_Adapter(null, Yaf_Application::app()->getConfig()->smarty); // 设置模板语言包函数 $smarty->getEngine()->register_function("getlang","Lang::smartygetlang"); $dispatcher->setView($smarty);}
设置标签
[smarty : yaf]smarty.left_delimiter = "{"smarty.right_delimiter = "}"application.view.ext="html"smarty.template_dir = APP_PATH "/application/views/"smarty.compile_dir = APP_PATH "/application/cache/compile"smarty.cache_dir = APP_PATH "/application/cache/"
阅读全文
0 0
- Yaf整合Smarty模板引擎
- Yaf整合Smarty模板引擎
- yaf 整合自定义 视图引擎(smarty)
- Yaf 结合用户自定义的视图(模板)引擎Smarty(Yaf + Smarty)
- Yaf通过composer整合Smarty
- ThinkPHP整合Smarty模板引擎操作mysql数据库
- CI框架与Smarty模板引擎实战整合
- 【smarty模板引擎】smarty模板引擎教程
- 模板引擎SMARTY
- 模板引擎SMARTY
- 模板引擎SMARTY
- 模板引擎SMARTY
- 模板引擎SMARTY
- 模板引擎SMARTY(zz)
- 模板引擎Smarty介绍
- 模板引擎SMARTY
- smarty模板引擎(一)
- Smarty模板引擎应用
- hdu 2089 不要62
- Python基础03 序列引用 【 例2:数轴、长整型】
- 有趣的排序——百度2017春招
- UVA 1513 Movie collection
- 日期差值
- Yaf整合Smarty模板引擎
- iOS- 快速开发一个app(一些包工具等)
- 【机器学习-西瓜书】二、模型评估:过拟合;自助法;交叉验证法
- scss 数学运算,加减
- C# ArrayList(数组列表)
- 自然语言处理学习(一):语言模型1.4
- 在做自动化测试之前你需要知道的
- android 日期工具类
- 自适应权值的立体匹配算法——AdaptWeight