Loading view outside view folder with CodeIgniter

后端 未结 7 2053
悲哀的现实
悲哀的现实 2020-12-03 12:44

I have the need to load a view from outside the scope of:

$this->load->view();

which appears to work from base/application/vie

7条回答
  •  隐瞒了意图╮
    2020-12-03 13:20

    Here is a much more straightforward answer that I found on the CodeIgniter forum at https://forum.codeigniter.com/thread-58412.html

    This is my ever-so-slight deviation from the solution presented by docmattman:

    class MY_Loader extends CI_Loader{
      public function __construct()
      {
        parent::__construct();
      }
    
      public function load_ext_view($view, $vars = array(), $return = FALSE)
      {
        $view_file = '/full/path/to/'.$view.'.php';
    
        if(file_exists($view_file)){
           $view_to_load = array('_ci_path'   => $view_file,
                                 '_ci_view'   => $view,
                                 '_ci_vars'   => $this->_ci_object_to_array($vars),
                                 '_ci_return' => $return
                                 );
    
           return $this->_ci_load($view_to_load);
        }
    
           return $this->view($view, $vars, $return);
        }
    }
    

提交回复
热议问题