12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\admin\controller\blog;
- use app\common\controller\Backend;
- use fast\Tree;
- use think\Controller;
- use think\Request;
- /**
- * 博客分类管理
- *
- * @icon fa fa-circle-o
- */
- class Category extends Backend
- {
- protected $noNeedRight = ['selectpage', 'check_element_available'];
- /**
- * BlogCategory模型对象
- */
- protected $model = null;
- protected $categorylist = [];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('BlogCategory');
- $this->view->assign("flagList", $this->model->getFlagList());
- $this->view->assign("statusList", $this->model->getStatusList());
- $tree = Tree::instance();
- $tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
- $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
- $categorydata = [0 => ['name' => __('None')]];
- foreach ($this->categorylist as $k => $v) {
- $categorydata[$v['id']] = $v;
- }
- $this->view->assign("parentList", $categorydata);
- }
- public function selectpage()
- {
- return parent::selectpage();
- }
- /**
- * 检测元素是否可用
- * @internal
- */
- public function check_element_available()
- {
- $id = $this->request->request('id');
- $name = $this->request->request('name');
- $value = $this->request->request('value');
- $name = substr($name, 4, -1);
- if (!$name) {
- $this->error(__('Parameter %s can not be empty', 'name'));
- }
- if ($id) {
- $this->model->where('id', '<>', $id);
- }
- $exist = $this->model->where($name, $value)->find();
- if ($exist) {
- $this->error(__('The data already exist'));
- } else {
- $this->success();
- }
- }
- }
|