开启模版布局环境下,指定模板路径无法定位布局文件

浏览:1146 发布日期:2015/04/01
3.2.3 - 普通 - 未处理
在开启模版布局模式时,如果display()直接指定模板路径,系统无法定位到布局模版而报错。 环境代码如下


配置文件:config.php// 模板引擎设置
'LAYOUT_ON'=>true, //开启布局模板
'LAYOUT_NAME'=>'Public/layout', //设置布局模版
控制器:IndexController.classs.phppublic function index(){
  $this->display('./App/Home/View/Public/query.html');
}
报错




-----------------------------------------------------
原因是常量“THEME_PATH”没有被定义。
感觉是ThinkPHP\Library\Think\View.class.php 第143行,parseTemplate()方法里面的问题。 然后增加了一句定义THEME_PATH的代码,问题消失。    /**
     * 自动定位模板文件
     * @access protected
     * @param string $template 模板文件规则
     * @return string
     */
    public function parseTemplate($template='') {
        if(is_file($template)) {
            // 获取当前主题的模版路径
           defined('THEME_PATH') or    define('THEME_PATH', $this->getThemePath(MODULE_NAME));
            return $template;
        }
        $depr       =   C('TMPL_FILE_DEPR');
        $template   =   str_replace(':', $depr, $template);
评论(
后面还有条评论,点击查看>>