autoload model works, load->model not work |
[eluser]josluimg[/eluser]
Hi, if I load a model with autoload it works, but If I load the model with load->model in the controller it doesn't work. My code: autoload.php Code: $autoload['model'] = array('User'); user.php Code: class User extends CI_Model userfull.php Code: class Userfull extends User Then in a controller Code: class Mobile extends REST_Controller I get the next error: Fatal error: Call to undefined method stdClass::getFullMedicalProfile() in ... The model doesn't load well, look at "stdClass", but if I put in autoload.php Code: $autoload['model'] = array('User','Userfull'); It works... I don't understand, what's wrong? :S Thanks community
[eluser]CroNiX[/eluser]
You can't have models extending models (except base CI_Model) without altering CI, adding a SPL autoloader or manually loading all models that extend other models. The reason it works in your autoload example is because you are explicitly loading both models individually. If you just load the "Userfull" model, it doesn't know it needs to load the "User" model first unless you manually tell it. This would probably work in your controller: Code: $this->load->model(array('User', 'Userfull'));
[eluser]hot_sauce[/eluser]
Code: // File name must be:
[eluser]josluimg[/eluser]
Thanks for your responses, but I think the problem is more trivial but I don't know which: Code: class Vip_relation extends CI_Model { Fatal error: Call to undefined method stdClass::add() What's wrong? I'm so newbie...
[eluser]hot_sauce[/eluser]
Code: class Vip_relation extends CI_Model {
[eluser]josluimg[/eluser]
Thanks hot_sauce, but I get: Fatal error: : Call to a member function add() on a non-object in the same error. Really, my code is: Code: $this->load->model("Vip_relation",);
[eluser]josluimg[/eluser]
I found a solution but I don't understand it: By stackoverflow Quote:When loading a model within a model, you need to get an instance of code igniter (instead of $this): Can anyone explain me? Because I'm loading a model in a Controller. Thanks
[eluser]hot_sauce[/eluser]
Code: /* Model Filename: vip_relation_model.php */
[eluser]InsiteFX[/eluser]
Look at your class name then look at the model name your loading, there both the same.
[eluser]josluimg[/eluser]
[quote author="InsiteFX" date="1403683188"]Look at your class name then look at the model name your loading, there both the same. [/quote] Are the same with right sintax (first letter capitalized, etc...). The calls name, model name or file name aren't the problem, besides I've try tried all combinations, bcz I went crazy. The solution I found is http://ellislab.com/forums/viewthread/245665/#1066626 |
Welcome Guest, Not a member yet? Register Sign In |