Smarty模板引擎:无法加载模板'file:header.tpl'

时间:2017-07-08 11:38:17

标签: php codeigniter templates smarty

我使用Smarty模板引擎和Codeigniter 3.0.0开发了CodeIgniter应用程序,一切运行良好。但升级Codeigniter后(从3.0.0升级到3.1.5)会出现Smarty错误:

  

无法加载模板'file:header.tpl'

Header.tpl落后于application / views / smarty_templates

我有一个可以回忆Smarty Libraries的codeigniter库:

<?php
require_once(APPPATH . 'third_party/smarty/libs/Smarty.class.php');

class CI_Smarty extends Smarty
{

    function __construct()
    {
        parent::__construct();
        $CI->load->config('smarty');
        $this->ci = & get_instance();

        log_message('debug',$this->setTemplateDir);

        $this->compile_dir = "/tmp/.smarty_templates_c";
        $this->template_dir = APPPATH . "views/smarty_templates";
        $this->assign('APPPATH', APPPATH);
        $this->assign('BASEPATH', BASEPATH);
        $this->assign('SITEURL', site_url());
        $this->assign('BASEURL', base_url()); 

        // Assign CodeIgniter object by reference to CI
        if (method_exists($this, 'assignByRef')) {
            $ci =& get_instance();
            $this->assignByRef("ci", $ci);
        }

        log_message('debug', "Smarty Class Initialized");
    }


    /**
     *  Parse a template using the Smarty engine
     *
     * This is a convenience method that combines assign() and
     * display() into one step.
     *
     * Values to assign are passed in an associative array of
     * name => value pairs.
     *
     * If the output is to be returned as a string to the caller
     * instead of being output, pass true as the third parameter.
     *
     * @access    public
     * @param    string
     * @param    array
     * @param    bool
     * @return    string
     */
    function view($template, $data = array(), $return = FALSE)
    {
        foreach ($data as $key => $val) {
            $this->assign($key, $val);
        }

        if ($return == FALSE) {
            $CI =& get_instance();
            if (method_exists($CI->output, 'set_output')) {
                $CI->output->set_output($this->fetch($template));
            } else {
                $CI->output->final_output = $this->fetch($template);
            }
            return;
        } else {
            return $this->fetch($template);
        }
    }
}

0 个答案:

没有答案