Where place render page code? |
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
That should probably be in your controller. Then after loading what you need you determine what is the right view to load.
Like a sad before, i dont want make copy past in each controller, i wanna make code dry
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/CodeIgnit...youts.html https://codeigniter4.github.io/CodeIgnit...dules.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');?>
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 |
Welcome Guest, Not a member yet? Register Sign In |