Welcome Guest, Not a member yet? Register   Sign In
error instance controller after loading a model
#1

[eluser]jorgeakanieves[/eluser]
I have modified codeigniter code doing a schema views.
Code:
a) execute controller:
admin.php
$this->load->library('users');

b) load a model from library...
users.php
$this->CI->load->model("model_users");

c)  return to controller and send the view to schema controller
admin.php
parent::sendContent($view);

d) from schema class load other controllers...
$view = $this->load->controller('header');

here is when i get the error because i try in controller function to do:
Code:
$obj =& new $name(); //new header()

and I get the error:
Code:
Undefined property: CI_header::$model_users
Fatal error: Call to a member function _assign_libraries() on a non-object in...Loader.php on line 1085

If I set to null the
Code:
$this->_ci_models
I resolve the problem... Why??

I supose I can´t use the model_users model after this....
#2

[eluser]Pascal Kriete[/eluser]
It resolves the problem because you no longer enter the loop in the loader.

The problem is quite clearly that you're trying to access $this->model_users from an object that has no model_users class variable. If you define model_users in the users controller it won't suddenly be copied over when you instantiate another one. $this is a reference to the current object.
#3

[eluser]jorgeakanieves[/eluser]
Then , it seems that this solution is a good practice?
#4

[eluser]wiredesignz[/eluser]
Check out Modular Extensions HMVC, in my signature, it may help.
#5

[eluser]jorgeakanieves[/eluser]
I´ve seen it. I think the problem is when I load the model...
Code:
//at the end of the model function your code is:
        
// instanciate and iniciate model on ci instance
$this->_me->$_alias =& new $model();
// assign libraries out of model class for the model class
$this->_assign_libraries_to($this->_me->$_alias);

// at the end of the function model my code is:
// instanciate and iniciate model on ci instance
$CI->$name = new $model();
// assign libraries on model class
$CI->$name->_assign_libraries();
// save models on CI
$this->_ci_models[] = $name;


you don´t save the model class object, isn´t it? is it the only difference?

Besides you assign libraries outside the model class but I think it´s insignificant.




Theme © iAndrew 2016 - Forum software by © MyBB