tags:

views:

675

answers:

1

I had created my own little lightweight framework for small projects, and now switched to Kohana.

But I wonder what's the way to go to achieve navigation hierarchies.

Example: I have a menu like this:

Home | Products | Support | Contact

In my old framework, when the user clicked on "Products", my framework knew which navigation layer this is and then my view attached an "_active" suffix to the css class of that menu item, so it's highlighted. The same for all parent navigation elements.

How are you setting up your site in Kohana to achieve something like this?

I thought about making one big layout view that contains the menu bar. There, I would have to implement all the logic to figure out which menu item has to be highlighted as active. Is there any clever mechanism for this, or would I just have to figure out from the current url somehow in a bunch of if-statements, if an url segment matches the menu item?

+2  A: 

You can use the uri::segment() method to get the current page, and then determine what your suffix should be based on that.

Example:

# Example Url: http://www.example.com/index.php/article/paris/hilton/
echo $this->uri->segment(3); // Returns 'hilton'

From there it's just a matter of checking the returned value against each one of your navigation links - when it maches, add your suffix.

Jonathan Sampson
So actually pretty much the same way ;)
Thanks
You could do the logic within the controller if you like. It's not going to make much of a difference, with the exception of keeping your logic in one location, namely the controller.
Jonathan Sampson