[eluser]überfuzz[/eluser]
I have a menu where there are some css-classes that are showing active link. The owner of the site want to have a link marked as active as default. At the moment I muster this in the view-file like this:
Code:
<?php foreach ($menu AS $value) //the array menu is stated in config and holds; segment, name and atribute.
{
$temp_seg = $this->uri->segment(1) ? $this->uri->segment(1) : 'home';
$class = ($temp_seg == $value['segment']) ? 'active' : '';
}
?>
<li class="<?php echo $value['attribute']; echo $class; ?>"><a href="<?php echo base_url() . $value['segment']; ?>" class="menu_font"><?php echo $value['name']; ?></a></li>
I'm thinking about moving parts of this to a model called systemdata and the MY_Controller, but I'm not exactly 100% sure of how and where I should insert the active css-class. So I just have to echo-loop the menu in the view-file.
Some ideas I have:
1. Put the loop in the config-file. No, I don't like to mess about with loops in config.php
2. Render it in the system model, when it's fetched from config.
3. render it in the MY_Controller, when it's received from model(system.php).
2 and 3 would mean that I have to loop through the array twice along the way just to get the menu ouput in the view-file. I've got one argument for doing it in the model, it's how I usually do this.
The question would be something like, is there a nifty way of doing this..?