1、新建一张表 id name pid path 插入几条数据
2、执行sql语句select id,name,pid,path,concat(path,'-',id) as bpath from think_cate order by bpath
请选择父级栏目
根栏目
新的栏目名称:
action
class CateAction extends Action {
function index(){
$Cate = D('Cate');
$list = $Cate->field("id,name,pid,path,concat(path,'-',id) as bpath")->order('bpath')->select();
foreach($list as $key=>$value){
$list[$key]['count'] = count(explode('-',$value['bpath']));
}
$this->assign('list',$list);
$this->display();
}
function add(){
$cate = D('cate');
if($vo=$cate->create()){
if($cate->add()){
$this->success('添加成功');
}else{
$this->error('添加失败');
}
//dump($vo);
}else{
$this->error($cate->getError());
}
}
}
?>
model
class CateModel extends Model {
protected $_auto=array(
array('path','tclm',3,'callback'),
);
function tclm(){
$pid = isset($_POST['pid'])? (int)$_POST['pid']:0;
if($pid==0){
return 0;
}
$map['id'] = $pid;
// echo $pid;
$list=$this->where($map)->find();
//dump($list);
$data = $list['path'].'-'.$list['id'];
return $data;
}
}
?>
请选择父级栏目
根栏目 for($i=0;$i {$vo['name']}
新的栏目名称: