I'm new to CodeIgniter. I've been loading common templates like header and footer in my controllers:
public function load_store_home_page($storeName) {
//Assign the page title
$global_data['page_title'] = $storeName;
//Load the header
$global_data['header'] = $this->load->view('header','', true);
...
But I'm doing this in every controller function. It seems messy. Is there a way I can somehow load these common elements globally?
I wouldn't recommend this, as there are occasions when you don't want to include neither a header nor a footer, due to redirects, sending files, json data or similiar. Instead, what I do, is simply that I include header and footer from the view itself.
However, if you insist, I suppose you could load the views from your classes constructor __construct()
and deconstructor __deconstruct()
.