id] = $value->url; $categories_name[$value->id] = $value->category_name; } $category_tree = obj_tree($categories); $where = []; if ($cid = $this->app->request->param('cid')) { $where['cid'] = $cid; } $data = $this->modelName::where($where)->field('id,cid,title,username,hits,sort,create_time')->order(['sort desc', 'id desc'])->paginate(); View::assign('category_tree', $category_tree); View::assign('categories_url', $categories_url); View::assign('categories_name', $categories_name); View::assign('data', $data); View::assign('cid', $cid); return View::fetch(); } public function save($id = 0, $cid = 0) { if ($this->app->request->isPost()) { $params = $this->app->request->param(); if (!$params['cid']) { $this->error('请选择栏目'); } if ($params['title'] == '') { $this->error("标题不能为空"); } $params['content'] = $params['editorValue']; unset($params['editorValue']); try { if ($params['id'] != 0) { $this->modelName::update($params); } else { $params['userid'] = $this->getSysUser()->userid; $params['username'] = $this->getSysUser()->username; unset($params['id']); $this->modelName::create($params); } } catch (\Exception $e) { $msg = $e->getMessage(); $this->error("错误提示:".$msg); } $this->success('操作成功', (string) url('index?cid='.$params['cid'])); } else { if (!$cid) { $this->error('请选择栏目'); } if ($id) { $data = $this->modelName::find($id); } else { $data = null; } $category_info = CategoryModel::field('id, parent_id, category_name')->find($cid); View::assign('cid', $cid); View::assign('category_info', $category_info); View::assign('data', $data); return View::fetch(); } } }