审查视图

application/admin/controller/Category.php 1.7 KB
Karson authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\common\model\Category as CategoryModel;
use fast\Tree;

/**
 * 分类管理
 *
 * @icon fa fa-list
 * @remark 用于统一管理网站的所有分类,分类可进行无限级分类
 */
class Category extends Backend
{

    protected $model = null;
    protected $categorylist = [];
20
    protected $noNeedRight = ['selectpage'];
Karson authored
21 22 23 24

    public function _initialize()
    {
        parent::_initialize();
25
        $this->request->filter(['strip_tags']);
Karson authored
26 27 28
        $this->model = model('Category');

        $tree = Tree::instance();
29
        $tree->init($this->model->order('weigh desc,id desc')->select(), 'pid');
Karson authored
30
        $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
Karson authored
31
        $categorydata = [0 => ['type'=>'all', 'name'=>__('None')]];
Karson authored
32 33
        foreach ($this->categorylist as $k => $v)
        {
Karson authored
34
            $categorydata[$v['id']] = $v;
Karson authored
35
        }
36 37 38
        $this->view->assign("flagList", $this->model->getFlagList());
        $this->view->assign("typeList", CategoryModel::getTypeList());
        $this->view->assign("parentList", $categorydata);
Karson authored
39 40 41 42 43 44 45 46 47 48 49 50 51
    }

    /**
     * 查看
     */
    public function index()
    {
        if ($this->request->isAjax())
        {

            //构造父类select列表选项数据
            $list = $this->categorylist;
            $total = count($list);
Karson authored
52
            $result = array("total" => 1, "rows" => $list);
Karson authored
53 54 55 56 57 58

            return json($result);
        }
        return $this->view->fetch();
    }
59 60 61 62 63 64 65 66 67 68
    /**
     * Selectpage搜索
     * 
     * @internal
     */
    public function selectpage()
    {
        return parent::selectpage();
    }
Karson authored
69
}