ThinkPhp5.1 implements menu tree output
汇英拓达杨凯瑞***
汇英拓达杨凯瑞*** 2019-04-29 15:02:07
0
0
1130

First create a method in common under application. Here we take the department data table department as an example.

The database table structure is as follows:

360截图16550428537093.png

  1. Find the following sub-departments and output them in tree form. The code in common is:

    function GetMenuID($pid){
    $list = \think\Db::table("department")
    ->where("pid",$pid)
    -->select();
    return $list;
    }

  2. #The code in the controller is:

    $list = Db::table('bumen')->where('pid',0)->select();//Find the parent column
    $ this->assign("list",$list);
    return $this->fetch();

  3. The code in the view is

    <select class="layui-select" name="dpid" id="dpid" required="required" lay-verify="dpid" autocomplete="off">
    {volist name="list" id="vo "}
                                                                                                                                                ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ##" id="po"}
                                                                                                                                                                                                                 name="$po['id']|GetMenuID=
    " id="co"}
                                                                                                                                                                                                                     ; |——{$co.dp_name}</option>


    ##Only three levels are written here. If there are more levels, and so on, the output results are as follows:


汇英拓达杨凯瑞***
汇英拓达杨凯瑞***

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!