多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
<?php namespace app\admin\Controller; use think\Db; use think\Request; use think\controller; use app\admin\Model\Cate as CateModel; Class Cate extends Controller{ /** * function add 添加栏目 * function edit 传入id修改 * function index 显示列表 * function del 删除栏目 */ public function add() { $cate = new CateModel(); if (Request::instance()->isPost()) { $data = input('post.'); $add = $cate->save($data); if ($add) { $this->success('增加栏目成功', 'cate/index'); } else { $this->error('增加栏目失败'); } } $cateList = $cate->cateTree(); $this->assign('cate', $cateList); return view(); } public function edit($id) { $cate = new CateModel(); if(request()->isPost()){ $data=input('post.'); $save = $cate->where('id', $data['id'])->save( $data); if ($save !== false){ $this->success('修改栏目成功!', url('index')); } else{ $this->error('修改栏目失败!'); } return; } //变量输出 $cates = $cate->find(input('id')); $cateList = $cate->cateTree(); $this->assign( array( 'caterList' =>$cateList, //栏目option 'cates' =>$cates, //栏目信息 )); return view(); } public function index() { $cate = new CateModel(); $cateList = $cate->cateTree(); $this->assign('cate', $cateList); return view(); } public function del($id) { $del=db('cate')->delete($id); if($del) { $this->success('删除栏目成功!',url('index')); } else { $this->error('删除栏目失败!'); } } }