20,359
社区成员
发帖
与我相关
我的任务
分享
function index(){
$cate=D('cate');
$list=$cate->field("id,catid,name,show,directory,sorting,pid,path,concat(path,'-',id) as bpath")->order('bpath')->select();
/*foreach($list as $key=>$value){
$list[$key]['count']=count(explode('-',$value['bpath']));
}*/
foreach($list as $key=>$value){
$list[$key]['count']=count(explode('-',$value['bpath']));
if ($value['pid'] == 0){
$list[$key]['name'] = $list[$key]['name'];
}else{
$list[$key]['name'] = $this->getStr($list[$key]['count']).' -'.$list[$key]['name'];
}
}
$this->assign('alist',$list);
$this->display();
}
private function getStr($p){
$str = "";
for($i=1;$i<$p;$i++){
$str.=" ";
}
return $str;
}
function add(){
$cate=new NavigationModel('cate');
if($vo=$cate->create()){
if($cate->add()){
$this->success('添加成功');
}else{
$this->error('添加栏目失败');
}
}else{
$this->error($cate->getError());
}
}
function add(){
换成你的内容模型
表单就换成内容参数值得表单
$cate=new NavigationModel('cate');
if($vo=$cate->create()){
if($cate->add()){
$this->success('添加成功');
}else{
$this->error('添加栏目失败');
}
}else{
$this->error($cate->getError());
}
}
`brand_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '1-1000为品牌1000以后为品牌下产品分类',
`name` varchar(255) NOT NULL COMMENT '名称',
`add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
`parent_id` int(5) unsigned NOT NULL DEFAULT '0' COMMENT '所属父栏目ID',
`arr_parent_id` varchar(255) NOT NULL DEFAULT '' COMMENT '所有父栏目',
`arr_child_id` text NOT NULL COMMENT '所有子栏目',
`is_child` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否有子栏目',
`level` int(2) unsigned NOT NULL DEFAULT '0' COMMENT '类型的深度级别,越是下级的分类,该值越大',
分类控制器添加
/**
* 新增
*/
public function add() {
$D=M('Brand');
if(IS_POST) {
$data = $D->create();
if($data) {
if(empty($data['name'])) {
$this->error('名称不能为空');
}
$id = $D->add();
if($id) {
$D->cacheClear(true);
$this->success('新增成功', U('index'));
} else {
$this->error('新增失败');
}
} else {
$this->error($D->getError());
}
} else {
$pid = I('get.parent_id', 0, 'intval');
//生成分类树
$this->assign('_Tree',From::selectCategory(getBrand(),$pid,'size="" class="col-xs-12 col-sm-2" name="brand_id"','请选择栏目',0,['idName'=>'brand_id']));
$this->meta_title = '新增';
$this->display('edit');
}
}