• 技术文章 >php教程 >PHP源码

    Yii的smarty插件 ESmartyViewRenderer 中的错误更正

    PHP中文网PHP中文网2016-05-25 17:13:08原创411
    Yii的smarty插件 ESmartyViewRenderer 中的错误更正

    class ESmartyViewRenderer extends CApplicationComponent implements IViewRenderer
    {
        省略..................
    
        public function renderFile($context,$sourceFile,$data,$return) {
            // current controller properties will be accessible as {$this.property}
            $data['this'] = $context;
            // Yii::app()->... is available as {Yii->...} (deprecated, use {Yii::app()->...} instead, Smarty3 supports this.)
            $data['Yii'] = Yii::app();
            // time and memory information
            $data['TIME'] = sprintf('%0.5f',Yii::getLogger()->getExecutionTime());
            $data['MEMORY'] = round(Yii::getLogger()->getMemoryUsage()/(1024*1024),2).' MB';
    
            // check if view file exists
            if(!is_file($sourceFile) || ($file=realpath($sourceFile))===false)
                throw new CException(Yii::t('yiiext','View file "{file}" does not exist.', array('{file}'=>$sourceFile)));
    
            $template = $this->smarty->createTemplate($sourceFile, null, null, $data, false);
    
            //render or return
            if($return){
                /*
                 * 源代码错误!
                 * return $template->fetch($sourceFile);
                 * 正确的调用方法如下,当指定参数时,必须指定所有相关的参数
                 * return $this->smarty->fetch($sourceFile, null, null, $data, false);
                 */
    
                return $template->fetch();    // 所有参数均从 $template 对象继承
            } else {
                /*
                 * 源代码错误!
                 * $template->display($sourceFile);
                 * 正确的调用方法如下,当指定参数时,必须指定所有相关的参数
                 * $this->smarty->display($sourceFile, null, null, $data, false);
                 */
    
                $template->display();    // 所有参数均从 $template 对象继承
            }
        }
    }
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:php得到文件扩展名 下一篇:PHP实现逆波兰式 - 计算工资时用

    相关文章推荐

    • php学习笔记之面向对象编程• php 站点使用XML文件做配置类• PHP禁止图片文件的被盗链函数• php实现连接access数据库并转txt写入的方法_php技巧• 使用simple_html_dom抓取oschina的新闻资讯

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网