thinkphp issues with dynamically loading menus

Source: Internet
Author: User
Thinkphp the problem of dynamically loading menus
Implementing Parent-child menu loading with two collections

foreach ($vo as $key = = $value) {
$vo [$key] [' ID ']= $value [' id '];
$vo [$key] [' MenuID ']= $value [' MenuID '];
$vo [$key] [' menuname ']= $value [' menuname '];
$vo [$key] [' ParentID ']= $value [' ParentID '];
$vo [$key] [' childID ']= $value [' childID '];
$vo [$key] [' url ']= $value [' url '];
}
}


foreach ($v 1 as $key 1=> $value 1) {
foreach ($v 2 as $key = + $value 2) {

if ($key 1+1>=count ($vo)) {
echo ' 1 ';
Break
}
if ($v 2[$key 1+1][' parentid ']== $vo [$key] [' menuid ']) {
$vo [$key 1+1][' ParentID ']= $value 2[' MenuID '];
Print_r ($vo [$key +1][' ParentID ']);

}
}
}
Dump ($VO)

Why the $vo and I think the menu directory structure is not the same ah?
------Solution--------------------
Recommended posts for Moderators: http://bbs.csdn.net/topics/390524563
------Solution--------------------
1. You can't see what you're going to do from your code.
2, if the outer loop is the parent menu, then the inner loop is to assemble the submenu data of the parent menu item
If that's the case, then your code is too inefficient.
TP provides the ability to correlate queries and return nested arrays, and does not require you to bother too much
3, the parameters passed is naturally the ID of the parent node, so that it can be successfully obtained under the ID of the first-level child node data
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.