0
点赞
收藏
分享

微信扫一扫

C语言的面向过程思想分析

七公子706 2023-07-14 阅读 43
php

效果图:

树状表格示意图

查询代码:

use app\model\Menu;

function getMenuList(string $uid)
{
    $list = Menu::where('pid', $uid)->select();
    foreach ($list as $val) {
        $val['children'] = getMenuList($val->uid);
    }
    return $list;
}

function getMenuBelong(string $uid)
{
    $has = [];
    $list = Menu::where('pid', $uid)->select();
    foreach ($list as $val) {
        $has[] = $val->id;
        $next = getMenuBelong($val->uid);
        $has = array_merge($has, $next);
    }
    return $has;
}

模型

<?php

namespace app\model;

use think\Model;

class Menu extends Model
{
    // 设置字段信息
    protected $schema = [
        'id' => 'int',
        'menu_title' => 'string',
        'menu_type' => 'int',
        'cate_uid' => 'string',
        'use_cate_uid' => 'int',
        'open_tag' => 'int',
        'uid' => 'string',
        'pid' => 'string',
        'order_sort' => 'int',
        'create_time' => 'int',
    ];
    protected $autoWriteTimestamp = 'create_time';
}
举报

相关推荐

0 条评论