Welcome Guest, Not a member yet? Register   Sign In
Generating a menu..
#3

[eluser]awpti[/eluser]
Actually, I'm not building any sort of breadcrumb or multi-tiered menu.

Just trying to, literally, figure out how to more efficiently add 'class="current"' to the menu item based on the URI segment.

While your idea might fit within the realm of what I want to do, I simply can't fathom how. I took the simple approach, but definately not the right approach.

See below: (I'm not proud of this - and yes, it's a library.


EDIT:

figured it out!

Code:
class Otnmenu {

    public $uri = '';

    function build_menu()
    {
        $menu = array(
            '/home'        => 'Home',
            '/blotter'    => 'TechBlotter',
            '/devblog'    => 'DevBlog',
            '/about'    => 'About',
            '/contact'    => 'Contact'
                    );
        foreach($menu as $key => $value)
        {
            $class = '';
            if($uri === str_replace('/', '', $key))
            {
                $class = 'class="content" ';
            }
            
            $menu_final .= '<a '.$class.'href="'.$key.'/">'.$value."</a><br />\n";
        }
        return $menu_final;
    }
}

In the controller:

Code:
$this->otnmenu->uri = $this->uri->segment(1);
$this->view->set('menu', $this->otnmenu->build_menu());


Messages In This Thread
Generating a menu.. - by El Forum - 01-17-2008, 08:59 PM
Generating a menu.. - by El Forum - 01-17-2008, 09:09 PM
Generating a menu.. - by El Forum - 01-17-2008, 10:39 PM
Generating a menu.. - by El Forum - 01-17-2008, 11:26 PM
Generating a menu.. - by El Forum - 01-17-2008, 11:46 PM
Generating a menu.. - by El Forum - 03-04-2009, 01:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB