![]() |
Call Model function from 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: Call Model function from Controller (/showthread.php?tid=74469) |
Call Model function from Controller - bustersg - 09-27-2019 While I know the concept of MVC but I am not sure if I am doing this the most 'efficient' way I have sql function in Model, I wan call it from Controller to pass it to View Below is how I do the 'flow'. Any shorter method or there a better way of doing? Controller PHP Code: $participants = new ParticipantModel(); Model PHP Code: <?php namespace App\Models; RE: Call Model function from Controller - InsiteFX - 09-28-2019 That's the right way to do it. RE: Call Model function from Controller - blaasvaer - 09-17-2020 Well, I'd guess that too. But it doesn't work! I've spent the whole morning trying to get basic stuff like this to work ... but CI 4 seems to have broken PHP itself, or something. RE: Call Model function from Controller - InsiteFX - 09-17-2020 You need to tell your model what table to use, most of the CodeIgniter Model parameters need to be setup in your model. I would open the system/Model.php and take a look at all the parameters it has to offer. PHP Code: <?php namespace App\Models; With that you should be able to use any of the CodeIgniter Model's methods. RE: Call Model function from Controller - blaasvaer - 09-17-2020 Yes, I managed to make a completely dynamic API ResourceController passing in all these properties as config settings. That way I avoid having a Controller AND a Model per resource. I just config them all in a single file ... as all the basic CRUD methods are the same across a ResouceController. Will see if this bite me later down the road ... but pretty confident for now ; ). |