Issue
I am using cakephp 3.6 and I have a modules tables in mysql database.
I want to create nested tree structure inside foreach loop. But i am not getting how to build loop in tree format.
Please help me to do so.
Below is my table strucure
id parent_id alias
119 NULL Controllers
120 119 Clients
121 120 add
122 120 Edit
123 119 Users
124 123 add
125 123 Edit
Expected Result
Clients
--add
--Edit
Users
--add
--Edit
Below is my code
<?php if(!empty($modulelist)) { foreach ($modulelist as $name){ ?>
<li class="last dd-item">
<input type="checkbox" name="short" id="short">
<label for="short" class="custom-unchecked">Clients</label>
<ul>
<li class="dd-handle">
<input type="checkbox" name="short-1" id="short-1">
<label for="short-1" class="custom-unchecked">add</label>
</li>
<li class="dd-handle">
<input type="checkbox" name="short-2" id="short-2">
<label for="short-2" class="custom-unchecked">edit</label>
</li>
</ul>
</li>
<?php }} ?>
Solution
Well you can use ORM behaviors Tree.
https://book.cakephp.org/3.0/en/orm/behaviors/tree.html
Based on Parent ID it will automatically generate TREE.
Answered By - Naveed Ramzan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.