Is there any way to load view ‘header’/’footer’ without calling $this->load->view('header') or $this->load->view('footer') in every controller? Maybe a template that can be use in every view?
Is there any way to load view ‘header’/’footer’ without calling $this->load->view(‘header’) or $this->load->view(‘footer’) in
Share
Here are a couple simple approaches to get you started:
Create a template class:
Usage in controller:
Use a master view file:
In the controller:
I prefer the
Templateclass approach, as it’s easy to add methods to append templates areas, load javascript files, and whatever else you need. I also prefer to automatically select the view file based on the method being called. Something like this:This would load
views/users/index.phpif the controller isUsersand the method isindex.