yaf的版本为3.3.2

百度出来的教程可能因为版本原因,均会报错:

Fatal error: Declaration of Smarty_Adapter::getScriptPath() must be compatible with Yaf_View_Interface::getScriptPath($request = NULL)。

主要原因是方法getScriptPath有些调整,

对代码进行修改,不报错了,具体代码如下:

<?php
Yaf_Loader::import( APPLICATION_PATH ."/application/library/Smarty/Smarty.class.php");
Yaf_Loader::import( APPLICATION_PATH . "/application/library/Smarty/sysplugins/smarty_internal_templatecompilerbase.php");
Yaf_Loader::import( APPLICATION_PATH . "/application/library/Smarty/sysplugins/smarty_internal_templatelexer.php");
Yaf_Loader::import( APPLICATION_PATH . "/application/library/Smarty/sysplugins/smarty_internal_templateparser.php");
Yaf_Loader::import( APPLICATION_PATH . "/application/library/Smarty/sysplugins/smarty_internal_compilebase.php");
Yaf_Loader::import( APPLICATION_PATH . "/application/library/Smarty/sysplugins/smarty_internal_write_file.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()) {Yaf_Loader::import(APPLICATION_PATH . '/application/library/Smarty/bootstrap.php');$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($request = null){return $this->_smarty->template_dir ?? null;}/*** 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));}/*** Allows unset() on object properties to work** @param string $key* @return void*/public function __unset($key){$this->_smarty->clear_assign($key);}/*** Assign variables to the template** Allows setting a specific key to the specified value, OR passing* an array of key => value pairs to set en masse.** @see __set()* @param string|array $spec The assignment strategy to use (key or* array of key => value pairs)* @param mixed $value (Optional) If assigning a named variable,* use this as the value.* @return void*/public function assign($spec, $value = null) {if (is_array($spec)) {$this->_smarty->assign($spec);return;}$this->_smarty->assign($spec, $value);}/*** Clear all assigned variables** Clears all variables assigned to Zend_View either via* {@link assign()} or property overloading* ({@link __get()}/{@link __set()}).** @return void*/public function clearVars() {$this->_smarty->clear_all_assign();}/*** Processes a template and returns the output.** @param string $name The template to process.* @return string The output.*/public function render($name, $value = NULL) {return $this->_smarty->fetch($name);}public function display($name, $value = NULL) {echo $this->_smarty->fetch($name);}}

修改bootstrap.php的代码

public function _initView(Yaf_Dispatcher $dispatcher) {//在这里注册自己的view控制器,例如smarty,firekylinYaf_Dispatcher::getInstance()->disableView(); //关闭其自动渲染
}public function _initSmarty(Yaf_Dispatcher $dispatcher) {$smarty = new Smarty_Adapter(null, Yaf_Registry::get("config")->get("smarty"));Yaf_Dispatcher::getInstance()->setView($smarty);
}

yaf框架整合smarty相关推荐

  1. yii2 smarty php,yii框架整合Smarty

    必须说明的是,本教程里所有的YII框架开发网站项目是整合Smarty来开发的,Smarty作为最成熟使用最多的模板之一,相信大家都比较熟悉.如果还有的同学不是很熟悉,可以参考Smarty教程.不过就算 ...

  2. php ci框架 模板引擎,详解CodeIgniter框架实现的整合Smarty引擎DEMO

    CodeIgniter框架实现的整合Smarty引擎DEMO示例 本文实例讲述了CodeIgniter框架实现的整合Smarty引擎.分享给大家供大家参考,具体如下: Smarty的模板机制很强大,一 ...

  3. php 5.5.12 yaf,yaf框架教程(5)- yaf框架的启动文件

    yaf框架的启动文件又被称为引导层,一般放在应用目录(application)下,主要作用是在框架启动时,初始化设置,注册插件,加载全局的方法等. 在Bootstrap类中, 所有以_init开头的方 ...

  4. php-yaf,Yaf框架安装指南

    这篇文章主要介绍了关于Yaf框架安装指南 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 说起PHP框架,很多人的印象都停留在一个由PHP实现的基于MVC的各种功能组合的代码包.极少有 ...

  5. php yaf框架模块化,YAF框架组成部分

    一.架构总览 YAF是经典的MVC架构,主要组件如下: (1)应用 YAF系统架构与生命周期的对象,由系统类Yaf_Application(启用命名空间的情况下是Yaf\Application)类完成 ...

  6. ssh(Struts+spring+Hibernate)三大框架整合-简述

    ssh(Struts+spring+Hibernate)三大框架配合使用来开发项目,是目前javaee最流行的开发方式,必须掌握: 注意: 为了稳健起见,每加入一个框架,我们就需要测试一下,必须通过才 ...

  7. CENTOS php 7.0 +nginx 环境下 安装yaf框架

    1 2 3 4  #php -v PHP 7.0.19 (cli) (built: May 12 2017 21:01:27) ( NTS ) Copyright (c) 1997-2017 The  ...

  8. linux 卸载yaf,LINUX操作系统怎么搭建YAF框架

    如何在已经搭建好的php环境下,继续搭建yaf框架环境?那么小编就在本文给大家介绍下搭建方法 LINUX操作系统怎么搭建YAF框架 命令: wget 地址参考图片 命令: tar zxvf yaf-2 ...

  9. springMVC和Shiro框架整合使用简单示例 【转】

    为什么80%的码农都做不了架构师?>>>    一.目录结构 首先是目录结构如图: 二.pom.xml文件 <project xmlns="http://maven. ...

最新文章

  1. 视觉SLAM前端特征检测与跟踪的思考
  2. 会话创建过程-创建Executor
  3. 微软中国职位[北京工作]
  4. C#将Json字符串反序列化成List对象类集合
  5. oracle database 11g 如何正确卸载
  6. 为什么这么多人看衰php,很多人都在看衰的SEO出路在哪儿?
  7. 支付宝借呗频繁借还款对征信有影响吗?
  8. OpenCV-数组加权和cv::addWeighted
  9. WCF Service Configuration Editor的使用
  10. 赋值运算不会提升数据类型,算术运算会提升类型
  11. 安排座位 java_如何安排领导座次
  12. vs不允许使用不完整的类型_擦痕破损严重老照片修复,基础工具辅助绘画,不使用素材完整修复...
  13. 为什么团建这么招人恨
  14. 边云协同,边缘云更出彩
  15. 996 log抓取过程
  16. Air202掉坑日记(3)——刷DTU固件(DTU版本)
  17. 趣味实践 利用Python定制可爱的举牌小人
  18. 尚硅谷JavaWeb教程
  19. 如何连接用户?苹果三星是该学习一下国产手机了
  20. 学习HCIA认证的day.1

热门文章

  1. 投影仪贵的和便宜的区别?业内公认千元投影仪性价比排行
  2. 【项目精选】springboot音乐网站与分享平台(论文+源码)
  3. C# 根据CPU硬盘获取机器码
  4. 关于思维和方法论类书籍的一些思考
  5. android ndk 编译虚幻4,[UE4]Android 打包步骤与keystore生成设置
  6. python列表推导式找出列表中长度大于5的名字
  7. QtextEdit乱码
  8. python代码提示expected_Expected conditions模块使用方法汇总代码解析
  9. java 制作自定义控件_自定义控件的三种方式
  10. 逆水寒江湖无限服务器等级,逆水寒·如何看待:开设服务器技能等级上限