ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
这个模型和添加的时候的模型是一样的,都需要 `adminCategoryTree` 我们访问的网址是:`agent/admin_category/edit/id/14.html` `$agentCategoryModel->adminCategoryTree($category['parent_id'], $id);` `$agentCategoryModel->adminCategoryTree(11, 14);` 说明:11是`四级分类1`(也就是五级分类1的上级),14是`五级分类1` ## 代码 ``` <?php namespace app\agent\model; use think\Model; use tree\Tree; class AgentCategoryModel extends Model { /** * 生成分类 select树形结构 * @param int $selectId 需要选中的分类 id * @param int $currentCid 需要隐藏的分类 id * @return string */ public function adminCategoryTree($selectId = 0, $currentCid = 0) { $where = ['delete_time' => 0]; if (!empty($currentCid)) { $where['id'] = ['neq', $currentCid]; } $categories = $this->order("list_order ASC")->where($where)->select()->toArray(); $tree = new Tree(); $tree->icon = ['&nbsp;&nbsp;│', '&nbsp;&nbsp;├─', '&nbsp;&nbsp;└─']; $tree->nbsp = '&nbsp;&nbsp;'; $newCategories = []; foreach ($categories as $item) { $item['selected'] = $selectId == $item['id'] ? "selected" : ""; array_push($newCategories, $item); } $tree->init($newCategories); $str = '<option value=\"{$id}\" {$selected}>{$spacer}{$name}</option>'; $treeStr = $tree->getTree(0, $str); return $treeStr; } } ```