douyun7285
2015-11-10 09:21
浏览 77
已采纳

移动到托管服务器时,调用未定义的方法CI_Loader :: template()

I am using CI 3 and all functions area working in my local server.

But when i uploaded it to the webhosting server it give me this error:

  Call to undefined method CI_Loader::template()

My controller "Main.php" has the code:

 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);                                   
    }
 }

And in the "My_Loader.php" has:

 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;
    }
}

What could be wrong?

Thanks in advance.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douxiaomang5640 2015-11-10 09:30
    已采纳

    Your core file names should match the class name.

    Try changing the file name to

    core/MY_Loader.php

    Instead of

    core/My_Loader.php

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • download92000 2015-11-26 07:57

    It has to be

    MY_Loader.php

    only. The prefix is fixed.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题