编写CodeIgniter应用程序时,我的控制器操作往往以如下几行开头:
$this->load->model('abc_model');
$this->load->library('ijk');
然后(仅为了完整性),他们的用法如下:
$this->abc_model->fetch_123();
$this->ijk->do_something();
扩展MY_Controller
是否会出现以下问题?
$this->model('zbc_model')->fetch_stuff();
$this->library('ijk')->do_something();
优点:
config/autoload.php
缺点:
答案 0 :(得分:2)
使用Phil Sturgeon的technique,将其添加到您的应用程序/ config / config.php
/*
| -------------------------------------------------------------------
| Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with cnfig/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
*/
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
@include_once( APPPATH . 'core/'. $class . EXT );
}
}