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

[eluser]enrico.simonetti[/eluser]
Hi guys,
I’ve found this unexpected behavior in CI 1.7.2.

I have a model and from his constructor I need to load something (it can be a library or another model).

It will fail.

This is affected even when autoloading a model/library.


The constructor can either be '__construct' or the className method.

If I execute from inside the constructor something like:
$this->load->model('test_model');
$this->test_model->test('a','b','c');

It will fail with:
Fatal error: Call to a member function model() on a non-object...

If instead I write the same code inside any other method it works fine.
The aim is to load some libraries/models for the whole class, not just for a method.

A workaround can be to get an instance of CI and load the library/model with his aid.

Eg:
$this->ci =& get_instance();
$this->ci->load->model('test_model');
$this->ci->test_model->test('a','b','c');


Did you guys experience this issue yourself?

Thanks


Messages In This Thread
Model can’t load or use libraries or other models from the constructor - by El Forum - 01-09-2010, 06:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB