CakePHP dynamic menu contents in layout

What I'm trying to do is put two dynamic navigation menus in my CakePHP layout (default.ctp). The main menu should have several levels (with the possibility of a drop-down list). The secondary menu is the one that shows the drop-down contents of the main menu in the left sidebar.

I read the CakePHP documentation, but I am confused about how to put these menus in the layout. I know that you have 4 different parts at the presentation level (as described in http://book.cakephp.org/2.0/en/views.html ):

  • view
  • the elements
  • layouts
  • Assistants

But with the knowledge that I have now, I think that none of these parts can be used to satisfy my needs. The navigation menu is the part you only load ONES in the layout, so it is not an element or helper. So what is the best practice ...

  • ... where to create a menu tree?
  • ... where / how is its echo in the layout file?

Can someone clear my problem? Thanks in advance!;)

+3
source share
1 answer

You can create a menu tree in a folder with items for example ...

element/top_menu.ctp

element / side_menu.ctp

Now you can include this menu in the layout as your requirement in a dianam state

eg #

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, indicate your condition .. and you can use the menu as your requirements from the Elemnts folder ......

+2
source

All Articles