![]() |
Where place render page code? - 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: Where place render page code? (/showthread.php?tid=84858) |
Where place render page code? - motoroller - 11-17-2022 Hello everyone, i need render page, but before i have a lot ruotine code, like set variables for template, get notifications for users choose template mobile or desktop, tell me please shopuld i put it code in model, helper? I dont want copy past same code in each controller, where better to put routine code for render page RE: Where place render page code? - cb32 - 11-17-2022 That should probably be in your controller. Then after loading what you need you determine what is the right view to load. RE: Where place render page code? - motoroller - 11-17-2022 Like a sad before, i dont want make copy past in each controller, i wanna make code dry RE: Where place render page code? - davis.lasis - 11-17-2022 First of all, you should read CI manual / documentation and from that understand what you can do / make hand-in-hand with what you need to achieve. This forum is not meant for teaching you understand programming and developing, or do a work for you, but for solving issues and helping each other. https://codeigniter4.github.io/CodeIgniter4/outgoing/view_layouts.html https://codeigniter4.github.io/CodeIgniter4/general/modules.html Long story short: Extend controller to some kind of base controller, where base controller always collects all "routine" stuff. Use view layouts with extending and creating sections. This is how i use CI benefits. This is jsut a basic and totally simple example. App/Controllers/BaseController.php PHP Code: <?php App/Controllers/MainController.php PHP Code: <?php App/Views/layout.php PHP Code: <!DOCTYPE html> App/Views/layout_header.php PHP Code: <head> App/Views/layout_footer.php PHP Code: <footer> App/Views/index.php PHP Code: <?=$this->extend('App\Views\layout');?> RE: Where place render page code? - Sprint - 11-17-2022 What is the most convenient method for example, in the controller Code: <code>function action_index(){ A: You could create a base controller with the common code and extend it in the other controllers. Code: <code>class Controller_Base extends Controller |