效果图:
文章来源地址https://www.toymoban.com/news/detail-597829.html
查询代码:
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';
}
文章来源:https://www.toymoban.com/news/detail-597829.html
到了这里,关于thinkphp模型递归查询的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!