How to use two models in a controller - 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: How to use two models in a controller (/showthread.php?tid=76413) |
How to use two models in a controller - hoffmanchan - 05-11-2020 Hello everyone, this is about codeigniter 4. I wanta use two models in a controller. But I have no idea how to solve it. Any suggestion for me please ? PHP Code: <?php namespace App\Controllers; RE: How to use two models in a controller - kilishan - 05-11-2020 Your example works just fine. Personally, I'd use the model() helper just to ensure I don't get more than 1 instance of the model created, but what you've done works fine. EDIT: if you're just using a model in a single method, there's no need to assign it to $this, just use a local variable: PHP Code: $authenticationModel = new AuthenticationModel(); RE: How to use two models in a controller - hoffmanchan - 05-11-2020 (05-11-2020, 06:40 AM)kilishan Wrote: Your example works just fine. Personally, I'd use the model() helper just to ensure I don't get more than 1 instance of the model created, but what you've done works fine. kilishan, thank for your reply. I will edit about this ~ |