How can I build navigation menu from categories and sub categories, like this:
http://mysite/categories/view/1/2
I tried menu builder 1.01 but it only works for acl users.
I also read this tutorial, but it was not helpful.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your first link doesn’t work.
Frankly, I’m not even sure I understand what you’re trying to do. The second link you supplied – I admit I only looked at the first code snippet – doesn’t use a database table. If you want your menu to be dynamic, as in based off controller actions, that makes sense. If you want it to be “dynamic” as in having dynamic control over menu items that you want to be able to have CRUD access to (you do know what CRUD stands for, right?), that’s a different (really really simple) story.
This is the most basic, bare-bones example imaginable. I literally slapped this together in fifteen minutes in my sandbox Cake 1.3.12 installation. I am pretty sure I got all the names changed for Cake 2 conventions, however some tweaking may be necessary. I tried to pare it down to the absolute basics and keep the code as clear as possible. Build it out as it suits you. Refer to the cookbook and remember to follow Cake convention at all times.
menus.menu.php.MenusController.php.Create the
/Views/Menusdirectory, and/views/Elements/Menus.CREATE TABLE
menus(idint(11) unsigned NOT NULL auto_increment,namevarchar(255) NOT NULL default ”,controllervarchar(255) NOT NULL,actionvarchar(255) NOT NULL,createddatetime NOT NULL,modifieddatetime default NULL,PRIMARY KEY (
id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Model code – Menu.php:
Controller code – MenusController.php:
Every MenusController action requires an [action name].ctp file in
/view/menus/.So create
/views/menus/index.ctpand/views/menus/add.ctp. What you put in /views/menus/index.ctp isn’t even terribly important, and /views/menus/add.ctp is the form you will use to add new menu items as desired:Now, create
/views/elements/menus/main.ctp:Finally, place the element in the layout so it appears on every page, regardless of view. If you are using the default cake layout, that means you should edit
/views/layouts/default.ctp. You probably want to put this item someplace sensible, such as the<div id="header">element. Insert theelement()call as follows:It may be necessary to add styling to your element to make it readable. Add styling to whatever stylesheet/s you may have (the default is cake.generic.css) as desired.
HTH. The cookbook is your friend.