实现添加无限极栏目名称
作者:互联网
第一步:创建一个栏目Controller 如:Category
数据库如:id(栏目ID)、tid(上级栏目)、neme(栏目名称)
as CategoryModel;
class Category extends Controller
{
public function add()
{
$category = new CategoryModel();
if (request()->isPost()) {
$data = input('post.');
if ($category->add($data)) {
$this->success('添加成功');
} else {
$this->error('添加失败');
}
}
$tptc = $category->catetree();
$this->assign('tptc' $tptc);
return view();
}
}
第二步:创建一个栏目的Model 如:Category
class Category extends Model
{
public function catetree()
{
$tptc = $this->order('id ASC')->select();
return $this->sort($tptc);
}
public function sort($data $tid = 0 $level = 0)
{
static $arr = array();
foreach ($data as $k => $v) {
if ($v['tid'] == $tid) {
$v['level'] = $level;
$arr[] = $v;
$this->sort($data $v['id'] $level + 1);
}
}
return $arr;
}
}
第三步:直接在模板引用无限极分类
{volist name="tptc" id="vo"}
{if condition="$vo['level'] neq 0"}|---{/if}{$vo.name}
{/volist}
标签:Category,栏目,level,无限极,添加,tptc,data,id 来源: https://blog.csdn.net/m0_37412958/article/details/78442103