Welcome Guest, Not a member yet? Register   Sign In
Model can’t load or use libraries or other models from the constructor
#5

[eluser]Donny Kurnia[/eluser]
I think this is not bug, but the way CI work.

$this->load->model, $this->load->library, and $this->load->helper should only used in controller, since it is the duty of controller to load required component.

If you want to load other model/library/helper from non-controller, such as library, model, or view, then you should do it by getting CI instance and use it to load required component.

The workaround you write is actually the way of CI work. You can open up build in library to see how it call other library and helper. One example, open up the Form_validation.php file in system/library folder. It will have this in the class constructor:

$this->CI =& get_instance();
...
$this->CI->load->helper('form');

So, given core library use this technique, then I can assume that this is CI way to load component from non-controller component.


Messages In This Thread
Model can’t load or use libraries or other models from the constructor - by El Forum - 01-10-2010, 02:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB