So I have a menu that I want to generate a main menu based on the authenticated user’s access level. No problem creating the menu, however I want to automatically create the generated menu in my “header” view. So in my controller I am calling the “header” view, but I don’t want to pass this dynamic part of the header like this:
$data['menu'] = 'Some Generated HTML Menu';
$this->load->view('header',$data);
I would rather it already be included in my header file, but I’m not exactly sure how to do this (aside from adding the $data declaration from inside of my constructor).
I don’t know if this will help you, but this was how I did my template system for the longest time before moving on to a more advanced method.
Top Head: views/inc/top_head.php
Bottom Head: views/inc/bottom_head.php
I do it this way so that I can split and add custom Javascript things and maybe bring in special case imports.
Footer: views/inc/footer.php
This is where you will put in your footer things etc….
Now we are at the point that we need to actually fill content in to the template
Index Page: /views/some_controller/index.php
So there, we have a quick template system. Now to show you what I have done for a controller
I hope this helped in some way or another. Mind you this is a quick write up. If I really wanted this to go into production, I would have moved the
_loadfunction into a parent class and extended it. I would also probably move thepage_datavariable along with it.