如何更改smarty html的文件路径?

时间:2016-02-07 13:35:07

标签: php codeigniter smarty codeigniter-3 smarty3

这是我的问题,我使用第三方(MX thingy)设置了Codeigniter(第3版),现在我尝试将Smarty(v.3)(模板)与系统集成。这就是我的所作所为:

  1. 从smarty.net下载最新的Smarty文件

  2. 编辑autoload.php

    $autoload['libraries'] = array('smarty');
    
  3. 复制smarty文件并将其粘贴到application / libaries / Smarty

  4. 在应用程序/库

    上创建了一个文件smarty.php
        <?php
    if (!defined('BASEPATH')) exit('No direct script access allowed');
    
    require_once( APPPATH.'libraries/Smarty/Smarty.class.php' );
    
    class CI_Smarty extends Smarty {
    public function __construct()
        {
            parent::__construct();
    
            $this->compile_dir =  APPPATH. "templates_c";
            $this->template_dir = VIEWPATH ;
            $this->plugins_dir = APPPATH.'libraries/smarty/plugins/';
            $this->assign( 'APPPATH', APPPATH );
            $this->assign( 'BASEPATH', BASEPATH );
    
            // 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");
        }
    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);
            }
        }
    }
    
  5. 皮肤文件夹的文件和文件夹结构如下:

    • 皮肤
    • &#39; - &GT;主题
    • &#39; - &GT;欢迎
    • &#39; ---&gt;文件(welcome_message.html)
  6. 欢迎conteroller中的代码(application \ modules \ welcome \ welcome.php)

    class Welcome extends MX_Controller {
    
        function __construct()
        {
            parent::__construct();
            $this->load->model('welcome_model','welcome');
        }
        public function index()
        {
            $this->smarty->display('welcome_message.html');
        }
    }
    
  7. 现在我尝试运行它,但是收到了以下错误消息:

        An uncaught Exception was encountered
    
        Type: SmartyException
    
        Message: Unable to load template file 'welcome_message.html'
    
        Filename: C:\xampp\htdocs\cleanci01\application\libraries\Smarty\sysplugins\smarty_internal_template.php
    
        Line Number: 139
    
        Backtrace:
    
        File: C:\xampp\htdocs\cleanci01\application\libraries\Smarty\sysplugins\smarty_internal_templatebase.php
        Line: 192
        Function: render
    
        File: C:\xampp\htdocs\cleanci01\application\libraries\Smarty\sysplugins\smarty_internal_templatebase.php
        Line: 109
        Function: _execute
    
        File: C:\xampp\htdocs\cleanci01\application\modules\welcome\Welcome.php
        Line: 14
        Function: display
    
        File: C:\xampp\htdocs\cleanci01\index.php
        Line: 294
        Function: require_once
    
  8. 我不知道我怎么会告诉他聪明他应该从&#34; skin / theme / welcome /&#34;而不是在FCPATH(enter image description here)。怎么可能发生这种情况?

    非常感谢任何帮助,谢谢你们!

0 个答案:

没有答案