![]() |
autoload model works, load->model not work - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: autoload model works, load->model not work (/showthread.php?tid=60761) Pages:
1
2
|
autoload model works, load->model not work - El Forum - 06-23-2014 [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 autoload model works, load->model not work - El Forum - 06-23-2014 [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')); autoload model works, load->model not work - El Forum - 06-24-2014 [eluser]hot_sauce[/eluser] Code: // File name must be: autoload model works, load->model not work - El Forum - 06-24-2014 [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... autoload model works, load->model not work - El Forum - 06-24-2014 [eluser]hot_sauce[/eluser] Code: class Vip_relation extends CI_Model { autoload model works, load->model not work - El Forum - 06-24-2014 [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",); autoload model works, load->model not work - El Forum - 06-24-2014 [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 autoload model works, load->model not work - El Forum - 06-24-2014 [eluser]hot_sauce[/eluser] Code: /* Model Filename: vip_relation_model.php */ autoload model works, load->model not work - El Forum - 06-25-2014 [eluser]InsiteFX[/eluser] Look at your class name then look at the model name your loading, there both the same. autoload model works, load->model not work - El Forum - 06-25-2014 [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 |