Just started with the framework Kohana and I’m understanding it better with the minute.
Now i’m trying to make the menu dynamic to the page the visitor is currently on.
So if the menu is – for example – like:
- Item1
- Item2
- Item3
and the user visits page example.com/kohana/item2 the menu should be like:
- Item1
- Item2
- Item3
So I have to check the URI and compare that with the menu items. I already tried it in different ways but all of them gave me errors.
For your information views/menu.php is now like:
<ul id="menu">
<li class="first"><?php echo HTML::anchor("", "item1"); ?></li>
<li><?php echo HTML::anchor("item2", "item2"); ?></li>
<li><?php echo HTML::anchor("item3", "item3"); ?></li>
<li><?php echo HTML::anchor("item4", "item4"); ?></li>
<li><?php echo HTML::anchor("item5", "item5"); ?></li>
<li><?php echo HTML::anchor("item6", "item6"); ?></li>
</ul><br/><br/>
I’m working with Kohana 3.2
Grab the ‘id’ parameter from the route (
$this->request->param('id')for instance) and compare it to your nav lists. You may also have to look at$this->request->controller()and$this->request->method(), those are very useful methods.P.S. All methods I’ve mentioned should be used in your controllers. Simply you could set some array called “nav” in your template controller and bind it to the template,and then through foreach iterate the menu items and compare item’s uri.