Category.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\model\Category as CategoryModel;
  5. use fast\Tree;
  6. /**
  7. * 分类管理
  8. *
  9. * @icon fa fa-list
  10. * @remark 用于统一管理网站的所有分类,分类可进行无限级分类
  11. */
  12. class Category extends Backend
  13. {
  14. protected $model = null;
  15. protected $categorylist = [];
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = model('Category');
  20. $tree = Tree::instance();
  21. $tree->init(CategoryModel::getCategoryArray(), 'pid');
  22. $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
  23. $categorydata = [0 => __('None')];
  24. foreach ($this->categorylist as $k => $v)
  25. {
  26. $categorydata[$v['id']] = $v['name'];
  27. }
  28. $this->view->assign("typelist", CategoryModel::getTypeList());
  29. $this->view->assign("parentlist", $categorydata);
  30. }
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. if ($this->request->isAjax())
  37. {
  38. //构造父类select列表选项数据
  39. $list = $this->categorylist;
  40. $total = count($list);
  41. $result = array("total" => $total, "rows" => $list);
  42. return json($result);
  43. }
  44. return $this->view->fetch();
  45. }
  46. }