cakephp - Cake PHP parent/child/grandchildren menus -
I want to display the menu with my children and the output of grand kids will be like this
Parents
- Children
Parents
- Children
My menu controller
< Code> public function buildTree ($ arr, $ parent_id = 0) {$ op = array (); Foreach ($ item as $ item) {if ($ item ['parent_id'] == $ parent_id) {$ op [$ item ['id']] = array ('name' = & gt; $ item ['name '],' Parent '= & gt; $ item [' parent_id ']); $ Children = buildtree ($ arrival, $ item ['id']); If (children) {$ from [$ item ['id']] ['parent_id'] = $ children; }}} Return $ op; }My visual element app \ view \ elements \ navigation.ctp
and ; $ Item ['menuItem'] ['name']. "& Lt; / li & gt;"; $ Child = $ menu_items-> Buildsubmenus ($ item ['MenuItem'] ['id']); Public relations ($ child); }? & Gt; & Lt; / Ul & gt;
Your controller needs to pass the tree and pass it to see. How to prepare it? It depends on your application, maybe you have to call the data base, maybe it's just a constant array, etc.
You will need to create your own format for the tree, for example: Child 11 [1] = & Gt; Array ([0] => Grandfather 121 [1] => Parent 122)) [1] = & gt; Parents 2 [2] => Array ([0] = & Gt; child 31))
Then you can pass it to see and loop the array. To do this, to create the menu, you can display the array You can use a recursive function .. or if you know that there are more than 3 If you do not have that level then you do not have to do anything with the cake. If you have a menu stored on the database, then you have 3
for
loops
=) Perhaps you can use DB to retrieve the menu, however you still have to pass it to see the function to display it
Hope it helps
Comments
Post a Comment