model = new \app\admin\model\content\article\Index;
// 移除权限检查
// $this->isSuperAdmin = $this->auth->isSuperAdmin();
$channelList = [];
$all = collection(Category::order("sort desc,id desc")->select())->toArray();
//允许的栏目 - 不区分权限,所有用户都可以选择所有栏目
$this->channelIds = Category::column('id');
$parentChannelIds = Category::column('parent_id');
$parentChannelIds = array_unique($parentChannelIds);
$tree = Tree::instance()->init($all, 'parent_id');
foreach ($all as $k => &$v) {
$state = ['opened' => true];
// 移除外部链接类型检查,因为表结构中没有type字段
// 不再检查权限,所有用户都可以看到所有分类
$channelList[] = [
'id' => $v['id'],
'parent' => $v['parent_id'] ?: '0',
'text' => htmlentities(__($v['title'])),
'expand' => true,
'state' => $state
];
$v['title'] = htmlentities($v['title']);
}
unset($v);
$tree = Tree::instance()->init($all, 'parent_id');
$categoryOptions = $tree->getTree(0, "", '');
$this->view->assign('categoryOptions', $categoryOptions);
$this->view->assign("statusList",StatusEnum::getMap());
$this->assignconfig('statusSearchList',json_encode(StatusEnum::getMap()));
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 编辑
*
* @param mixed $ids
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
// 获取当前文章分类ID(确保字段名称正确)
$categoryId = isset($row['category_id']) ? $row['category_id'] : 0;
// 获取所有分类,不限制权限
$all = collection(Category::order("sort DESC,id DESC")->select())->toArray();
foreach ($all as $k => &$v) {
$v['title'] = htmlentities($v['title']);
}
// 初始化树结构并生成分类选项
$tree = Tree::instance()->init($all, 'parent_id');
$categoryOptions = $tree->getTree(0, "", $categoryId);
$this->view->assign('categoryOptions', $categoryOptions);
$this->view->assign("row", $row);
return parent::edit($ids);
}
}