在 application/core/ 创建一个文件 MY_Loader.php
<?php
class MY_Loader extends CI_Loader {
function __construct() {
parent::__construct();
$CI =& get_instance();
$CI->load = $this;
}
public function ext_view($view, $vars = array(), $return = FALSE){
$_ci_ext = pathinfo($view, PATHINFO_EXTENSION);
$view = ($_ci_ext == '') ? $view.'.php' : $view;
return $this->_ci_load(array(
'_ci_vars' => $this->_ci_object_to_array($vars),
'_ci_path' => $view, '_ci_return' => $return));
}
}
在 application/core/ 创建一个文件 MY_Controller.php
<?php
class MY_Controller extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load =& load_class('Loader', 'core', 'MY_');
$this->load->initialize();
log_message('debug', "Controller Class Initialized");
}
}
使用MY_Controller
代替,CI_Controller
您可以访问 ext_view 方法
$this->load->ext_view(path/to/the/view/file,@param2,@param3);
前任:
class Welcome extends MY_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->ext_view('/path/to/view');
}
}