thinkphp如何实现无限分类的添加——伪原创
效果如下:
首页,我有一个分类的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 (); //开源软件:phpfensi.com if ( $dc ){ $this ->success( '删除成功!' ); } else { $this ->error( '删除失败!' ); } }查看更多关于thinkphp如何实现无限分类的添加——伪原创 - Th的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did6334