-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Header and Footer and Menu on every page jedd
Category:Approaches::Header and Footer and Menu on every page
[b]Overview:[/b]
I have three things that I want to see on pretty much every page: [b]o[/b] header - page title, login status, and maybe some links [b]o[/b] footer - links, page rendering stats, and some advertising back to the CI site! [b]o[/b] menu - generated from an array (not DB) containing only category and sub-category levels
Because I want to see them pretty much on every page, and I consider the process to be inexpensive, I am happy to have them created on [i]every[/i] page load.
If you don't want this - you could modify this approach by putting some smarts into MY_Controller to identify whether to create the vars or not - but this might be messier than other Approaches to the problem.
[b]Approach (brief):[/b]
I [url="http://codeigniter.com/user_guide/general/core_classes.html"]extend the core Controller[/url] and make [b]MY_Controller.php[/b].
Within MY_Controller I call out to view files that generate sub-sets, typically
These view outputs are stored into variables within the [b]$this->data[/b] array. The primary view file then just displays these data using simple echo statements.
[b]Approach (in detail):[/b]
Let's work backwards from the end result - I think this will make more sense.
This is roughly what my [color=green][b]primary view file (default.php)[/b][/color] looks like. Note that this is what [b]all[/b] my pages are rendered through.
[code] <html> <head> <?php echo "\n". link_tag('assets/stylesheets/COMMON.css'); echo "\n". link_tag('assets/stylesheets/'. $theme .'.css'); ?>
<title> <?php echo $title; ?> </title> </head>
<body>
<?php ?>
<div id="div_topbar_wrapper">
<?php echo $top_bar_view; ?>
</div>
<div class="break">
</div>
<div id="div_torso_wrapper">
<div id="div_navigation_menu">
<?php echo $main_menu_view; ?>
</div>
<div id="div_main_content">
<?php echo $main_content_view; ?>
</div>
</div>
<div class="break">
</div>
<div id="div_footer_wrapper">
<table width="100%">
<tr width="100%">
<td width="25%" align="left">
<b>
<!-- Can't pre-render this, as it'll throw the reported results -->
Rendered in {elapsed_time}s, and {memory_usage}.
</b>
</td>
<td width="50%" align="center">
$other_stuff
</td>
<td width="25%" align="right">
Developed using
<?php echo anchor_popup ("http://codeigniter.com/", "Code Igniter"); ?>
</td>
</tr>
</table>
</div>
</body> </html> [/code]
Now let's look at what goes into one of those view snippets that I'm echo'ing there. My top view contains three divs, generated separately, so not a good candidate example. My menu is lengthy, but most people understand menus, and I happen to generate a slightly different menu if the logged in user is [b]admin-equiv[/b], so it's probably a quite instructive choice.