tp5造成的一个困扰

浏览:2673 发布日期:2016/09/23 分类:ThinkPHP5专区 关键字: tp5 困扰
现在tp5的控制器有两种方式调用视图,控制器直接继承Controller,用$this->fetch();调用,是没问题的,但是还有一种调用方式View::instance()->fetch();
在用第二种方式的时候,就出现下面这个问题了
==========分割线===========
tp5我看跟zf2有相似的地方,想把模板文件的后缀由html改成phtml,发现改配置文件不好用,查了查tp5的View文件,发现它没有调用配置文件的信息    public function engine($options = [])
    {
        if (is_string($options)) {
            $type    = $options;
            $options = [];
        } else {
            $type = !empty($options['type']) ? $options['type'] : 'Think';
        }

        $class = false !== strpos($type, '\\') ? $type : '\\think\\view\\driver\\' . ucfirst($type);
        if (isset($options['type'])) {
            unset($options['type']);
        }

        $this->engine = new $class($options);
        return $this;
    }
本人在代码里做如下修改    public function engine($options = [])
    {
        if (is_string($options)) {
            $type    = $options;
            $options = [];
        } else {
            $type = !empty($options['type']) ? $options['type'] : 'Think';
        }

        $class = false !== strpos($type, '\\') ? $type : '\\think\\view\\driver\\' . ucfirst($type);
        if (isset($options['type'])) {
            unset($options['type']);
        }
        //tu6ge 添加 todo
        if(empty($options)){
            $options = Config::get('template');
        }
        $this->engine = new $class($options);
        return $this;
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>