<?php if (!defined('BASEPATH')) exit('No direct access allowed.');
class MY_Controller
extends CI_Controller
{
public function __construct
()
{
$this->init_property();
parent
::__construct
();
}
protected function init_property
()
{
foreach (is_loaded
() as $var => $class) {
$this->$var = null;
}
$this->load = null;
}
protected function _is_model
($name)
{
if (strpos($name, '_model') !== false) {
return true;
}
return false;
}
public function __get
($name)
{
if ($this->_is_model
($name)) {
$this->load->model($name);
} else {
$this->load->library($name);
}
return $this->$name;
}
}
?>
/*
$rs = $this->form_validation->run();
$this->post_model->test();
然后其他的控制器继承 MY_Controller 类, 在控制器中类库和MODEL直接用就可以了,不需要再手动加载了。
*/