When writing CodeIgniter applications my controller actions tend to begin with a few lines as below:
$this->load->model('abc_model');
$this->load->library('ijk');
And then (just for completeness) they're used as follows:
$this->abc_model->fetch_123();
$this->ijk->do_something();
Would there be anything too wrong about extending MY_Controller
so that the following was possible?
$this->model('zbc_model')->fetch_stuff();
$this->library('ijk')->do_something();
Pros:
- Classes aren't loaded until they're actually used
- Wouldn't need to auto-load any classes using
config/autoload.php
- Slightly cleaner code (arguably)
Cons:
- An extra method call for every access (generally just returning the already loaded instance though)
- Slightly messier code (arguably)