【问题标题】:Call to undefined method CI_Loader::template() when move to hosting server移动到托管服务器时调用未定义的方法 CI_Loader::template()
【发布时间】:2015-11-10 09:21:08
【问题描述】:

我正在使用 CI 3 和在我的本地服务器上工作的所有功能区域。

但是当我将它上传到虚拟主机服务器时,它给了我这个错误:

  Call to undefined method CI_Loader::template()

我的控制器“Main.php”有代码:

 class Main extends CI_Controller {
    function __construct() {
        parent::__construct();                  
        /* enable session */            
        //$this->output->enable_profiler(TRUE);             
    }

    public function index() {
        if ( ! file_exists(APPPATH.'/views/admin/main.php'))
        {
            /* Whoops, we don't have a page for that! */
            show_404();
        }


        $data['menu'] = $this->load->view('templates/menu', $data, TRUE);                           
        $data['title'] = "EGB | Main"; 
        $this->load->template('admin/main', $data);

        //$this->load->view('admin/main', $data);                                   
    }
 }

并且在“My_Loader.php”中有:

 class MY_Loader extends CI_Loader {
    public function template($template_name, $vars = array(), $return = FALSE)
    {
         if($return):
            $content  = $this->view('templates/header', $vars, $return);
            $content .= $this->view($template_name, $vars, $return);
            $content .= $this->view('templates/footer', $vars, $return);

            return $content;
        else:
            $this->view('templates/header', $vars);
            $this->view($template_name, $vars);
            $this->view('templates/footer', $vars);
        endif;
    }
}

可能出了什么问题?

提前致谢。

【问题讨论】:

  • 尝试使用文件名MY_Loader.php 而不是My_Loader.php
  • 是的,你说得对!我错过了!谢谢:)

标签: php codeigniter undefined-function


【解决方案1】:

您的核心文件名应与类名匹配。

尝试将文件名更改为

核心/MY_Loader.php

代替

核心/My_Loader.php

【讨论】:

    【解决方案2】:

    必须是

    MY_Loader.php

    仅限。前缀是固定的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 2017-12-12
      • 2013-02-15
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      相关资源
      最近更新 更多