I am autoloading my model now, and accessing it directly in the view file. I find this a lot easier than initializing the model in EVERY single controller.
An alternative would be to extend the Controller class (e.g. MY_Controller), and place the call to the repeating function(s) in the constructor for MY_Controller. Then of course any controller that uses that code will need to extend MY_Controller instead of simply Controller.
That way, you maintain the MVC pattern a little more strictly.
Example:
system/application/libraries/MY_Controller.php
class MY_Controller extends Controller
{
function MY_Controller()
{
parent::CI_Base();
$this->_ci_initialize();
log_message('debug', 'MY_Controller Class Initialised');
// now put all the code you want executed within every controller here
}
}
system/application/controllers/start.php
class Start extends MY_Controller
{
function __construct()
{
parent::MY_Controller();
}
}
