![]() |
loading template only once ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: loading template only once ? (/showthread.php?tid=67436) |
loading template only once ? - Coool6 - 02-22-2017 Hello to the nice community ! I'm a beginner in CI (but not in PHP), i saw the CI logic is to load the template files in the controller in each method. At the end you load the same files all the time, and it makes heavy controller files for nothing. Code: $this->load->view('templates/header', $data); There is an easier solution to just load it once in your controller or even in your project (for example if you use the same template for the whole project ? Or maybe just to have one template.php file and loading the content inside ? If you can help me, you will be lovely ! Thanks a lot ![]() RE: loading template only once ? - InsiteFX - 02-22-2017 Use a MY_Controller RE: loading template only once ? - Coool6 - 02-22-2017 (02-22-2017, 11:10 AM)InsiteFX Wrote: Use a MY_Controller Thanks ! But if i use Code Igniter, it's better to use the CI_controller. So what could be the solution with the CI_controller ? RE: loading template only once ? - ciadmin - 02-22-2017 Er, core/MY_Controller *is* how you use the CI_Controller for the purpose you describe. https://www.codeigniter.com/user_guide/general/core_classes.html See https://github.com/bcit-ci/codeigniter-website for an example. RE: loading template only once ? - eduard.pantazi - 02-22-2017 For me worked very well with new Controller, like: Create a MY_Controller.php in application/core with this: PHP Code: <?php And this is it. To work with it, in your controllers use like this: PHP Code: .... Now you have a template function that load the header and footer everytime and also load the page content and you can pass trough data to show on the header,page content and footer. Hope is usefull. Have a nice day, Eduard. RE: loading template only once ? - InsiteFX - 02-23-2017 PHP Code: <?php |