效果如下:
首页,我有一个分类的class的表.
具体代码分为:显示和添加分类的代码:
- public function right(){
- $m=M('Class');
- $list=$m->field("id,name,pid,path,concat(path,id) as bpath")->order('bpath')->select();
- foreach($list as $k=>$value){
- $list[$k]['count']=substr_count($value['path'],",")-1;
- }
- $this->assign('alist',$list);
- $this->display();
- }
- //添加分类
- public function addclass(){
- $m=D('Class');
- if(!$m->create()){
- $this->error($m->getError());
- }
- $list=$m->add();
- if($list){
- $this->success("添加成功!!");
- }
- else
- {$this->error('添加失败!');
- exit;
- }
- }
添加时有个表格提交,所以就有个自动创建:ClassModel.class.php
删除分类:
- //删除分类
- public function delclass(){
- $m=M('Class');
- $where['id']=$_POST['pid'];
- $where['path']=array("like","%{$_POST['pid']}%");
- $where['_logic']='or';
- $dc=$m->where($where)->delete();
- //开源软件:Vevb.com
- if($dc){
- $this->success('删除成功!');
- }else{
- $this->error('删除失败!');
- }
- }
新闻热点
疑难解答
图片精选