修正文章新增分类获取

This commit is contained in:
1099438829 2021-02-21 23:58:42 +08:00
parent 006b4c83cb
commit 348c1d3c56
4 changed files with 36 additions and 5 deletions

View File

@ -130,4 +130,23 @@ if (!function_exists('get_dir'))
}
return $dirArray;
}
}
}
if (!function_exists('get_tree_list'))
{
/*无限分类*/
function get_tree_list(&$list,$pid=0,$level=0,$html='|—')
{
static $tree = array();
foreach ($list as $v) {
if ($v['pid'] == $pid) {
$v['sort'] = $level;
$v['html'] = str_repeat($html, $level);
$tree[] = $v;
get_tree_list($list, $v['id'], $level + 1);
}
}
return $tree;
}
}

View File

@ -109,7 +109,13 @@ class Article extends AuthController
*/
public function add()
{
$this->assign("category",cModel::selectByType(2));
$where = [
'name' => '',
'status' => ''
];
$category = cModel::systemPage($where);
$category = get_tree_list($category);
$this->assign("category",$category);
return $this->fetch();
}
@ -122,7 +128,13 @@ class Article extends AuthController
*/
public function edit(Request $request)
{
$this->assign("category",CModel::selectByType(2));
$where = [
'name' => '',
'status' => ''
];
$category = cModel::systemPage($where);
$category = get_tree_list($category);
$this->assign("category",$category);
$this->assign("info",aModel::get($request->param(['id'])));
return $this->fetch();

View File

@ -38,7 +38,7 @@
<select name="category_id" class="form-control" id="category_id">
<option value="0">请选择</option>
{volist name="category" id="vo"}
<option value="{$vo.id}">{$vo.title}</option>
<option value="{$vo.id}">{$vo.html}{$vo.title}</option>
{/volist}
</select>
</div>

View File

@ -38,7 +38,7 @@
<select name="category_id" class="form-control" id="category_id">
<option value="0">请选择</option>
{volist name="category" id="vo"}
<option value="{$vo.id}" {if $vo.id == $info.category_id}selected{/if}>{$vo.title}</option>
<option value="{$vo.id}" {if $vo.id == $info.category_id}selected{/if}>{$vo.html}{$vo.title}</option>
{/volist}
</select>
</div>