3
votes

What I'm trying to do is to put two dynamic navigation menus in my CakePHP layout (default.ctp). The main menu should have multiple levels (with a dropdown functionality). The secondary menu is the one that shows the dropdown content of the main menu in a left sidebar.

I've read the CakePHP documentation but I'm confused how to fit those menus in the layout. I know that you have 4 different parts in a view layer (as documented in http://book.cakephp.org/2.0/en/views.html):

  • views
  • elements
  • layouts
  • helpers

But with the knowledge I have right now, I think none of this parts can be used to fill my needs. A navigation menu is a part that you only load ONES in a layout, so it isn't an element or a helper. So what's the best practice...

  • ... where to create the menu tree?
  • ... where / how to echo it in the layout file?

Can anybody clearify my issue? Thanks in advance! ;)

1

1 Answers

2
votes

You can create your menu tree in element folder for example ...

element/top_menu.ctp

element/side_menu.ctp

now you can include these menu in layout as your requirement at dyanamic condition

for example #

if(#user is admin)
{
   echo $this->Element('top_menu');
}
else if(# user is registered)
{
   echo $this->Element('side_menu');
}
else
{
     echo $this->Element('top_menu');
    echo $this->Element('side_menu');
}

Here put your condition ..and you can use menus as your requirements from Elemnts folder......