The short answer is that CodeIgniter doesn't work the way you want it to. At the stage that you're trying to access a model, CodeIgniter hasn't loaded the required classes and it isn't available. Depending on exactly what you're trying to achieve, there may be another way to achieve this - without using a hook/using a later hook?
Viewing /system/core/CodeIgniter.php
will show when each hook is called and when other tasks are performed; loading routing, loading global functions etc.
If you insist on using this hook, then you could add this: load_class('Model', 'core');
at the top of your model file (before you declare the class), but this would be a very dirty fix.
Make sure your class names follow the correct naming convention - tester
should be Tester
.
Edit: as you want to run the same code on every call (assuming every controller call), this is a possible solution:
Extend the core controller, and use this new controller as a base controller for all other controllers (as they will be sharing the same functionality). In the constructor of this new base controller, add the functionality that you want to run on every call. The code in this constructor will be called before any other code in any of your controllers.
Create the following file, application/core/MY_Controller.php
.
class MY_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
// Do whatever you want - load a model, call a function...
}
}
Extend every controller in application/controllers
, with MY_Controller
, rather than CI_Controller
.
class Welcome extends MY_Controller {
function __construct()
{
parent::__construct();
}
// Your controllers other functions...
}