Using model in another model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Using model in another model (/showthread.php?tid=75301) |
Using model in another model - bonaxcrimo - 01-23-2020 how can i call model in anothe model in ci4 in ci3 i can use PHP Code: $this->load->model(modelName); thanks RE: Using model in another model - kilishan - 01-23-2020 PHP Code: $userModel = new App\Models\UserModel(); RE: Using model in another model - littlej - 01-24-2020 Hello, @kilishan : I looked at the documentation, and I saw nothing about how to load a model. I think it should be one of the first things on the "Using CodeIgniter’s Model" page. I know it is not complicated, but some people might need this information. So, I think I will update the documentation when I have a little time ;-) @bonaxcrimo : You can call a model like this: PHP Code: // Load the Users model Then you will be able to use it like this: PHP Code: // Find a specific user And you will find more info here: https://codeigniter4.github.io/userguide/models/model.html RE: Using model in another model - MGatner - 01-24-2020 @littlej More docs are always welcome, but I also think it is fair to say that specific pages in the docs assume knowledge of framework general principles. We have a section on namespaces and how things are different from CI3 and develops coming from 3 definitely need to read those before diving in. RE: Using model in another model - PaulD - 01-24-2020 Hi, Although I agree with MGatner, that some knowledge has to be assumed, I think littlej is right on this instance IMHO. Many people learning PHP will be using CI, or using a framework for the first time, or just trying CI out for the first time and looking for an expected 'CI' way to load a model. The docs for Models should definitely have that intro info in there, otherwise many people can be left scratching their heads or searching the forum or even worse, giving up with CI at a very early stage. For instance like CI3: https://codeigniter.com/user_guide/general/models.html#loading-a-model It also shows how easy CI is to use. A persuasive feature for new users. |