model = new CategoryModel(); $this->assign('typeList',site_config("dictionary.categorytype")); } #[Route("*","index")] public function index() { if($this->request->isAjax()){ $result = ['total' => 1000, 'rows' => $this->getCatelist()]; return json($result); } return $this->_index(); } #[Route("POST,GET","add")] public function add() { if(!$this->request->isPost()){ $catelist=$this->getCatelist(); foreach ($catelist as $k => $v) { $categorydata[$v['id']] = $v; } $this->assign('parentList',$categorydata); } return $this->_add(); } #[Route("POST,GET","edit")] public function edit() { if(!$this->request->isPost()){ $catelist=$this->getCatelist(); foreach ($catelist as $k => $v) { $categorydata[$v['id']] = $v; } $this->assign('parentList',$categorydata); } return $this->_edit(); } private function getCatelist() { $tree = Tree::instance(); $list=$this->model->order('weigh desc,id desc')->where(function ($query){ $type = $this->filter("type"); if($type){ $query->where('type',$type); } })->select()->toArray(); $tree->init($list, 'pid'); $categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name'); return $categorylist; } }