class Essay extends Admin { public function index() { $data = Db::table('admin_essay')->order('order')->paginate(); $page = $data->render(); return ZBuilder::make('table') ->setTableName('admin_essay') //->addOrder(['update_time','desc']) // 添加排序 ->setSearch('title') ->addColumns([ ['imgurl', '封面','picture'], ['title', '标题'], ['original', '原创'], ['type','文章类型'], ['update_time','修改时间','datetime'], ['right_button', '操作', 'btn'], ]) ->addTopButtons('add,delete') ->addRightButton('delete', ['data-tips' => '删除后无法恢复。']) ->addRightButton('edit') ->setRowList($data)// 设置表格数据 ->setPages($page) // 设置分页数据 ->fetch(); // 渲染模板 } public function add($id = null) { if($this->request->isPost()) { $data = $this->request->post(); $Messay = new Messay(); $rtn = $Messay->class_add($data); if ($rtn) { $this->success("新增成功!",'index'); } else { $this->error('新增失败'); } } return ZBuilder::make('form') ->addRadio('type', '选择分类', '', ['投资' => '投资', '移民' => '移民', '留学' => '留学','房产'=>'房产']) ->addSwitch('original', '是否原创', '', '0') ->addFormItems([ ['hidden','id'], ['text:5', 'title', '标题'], ['text:5', 'source', '来源'], ['text:5', 'writer', '作者'], ['text:5', 'desc', '描述'], ['text:5', 'keywords', '关键词'], ['image', 'imgurl', '封面'], ['text:3', 'order', '排序'], ]) ->addSwitch('rec', '推荐', '', '0') ->addUeditor('content', '内容') ->fetch(); } public function edit($id = null) { if($this->request->isPost()) { $data = $this->request->post(); $rtn = Db::table('admin_essay')->update($data); if ($rtn) { $this->success("修改成功!",'index'); } else { $this->error('修改失败'); } } $data = Db::table('admin_essay')->where('id',$id)->find(); return ZBuilder::make('form') ->addRadio('type', '选择分类', '', ['投资' => '投资', '移民' => '移民', '留学' => '留学','房产'=>'房产']) ->addSwitch('original', '是否原创', '', '0') ->addFormItems([ ['hidden','id'], ['text:5', 'title', '标题'], ['text:5', 'source', '来源'], ['text:5', 'writer', '作者'], ['text:5', 'desc', '描述'], ['text:5', 'keywords', '关键词'], ['image', 'imgurl', '封面'], ['text:3', 'order', '排序'], ]) ->addSwitch('rec', '推荐', '', '0') ->addUeditor('content', '内容') ->setFormData($data) ->fetch(); } }