thinkphp无限分类应用,仿织梦栏目管理

jerry thinkphp 2015年11月18日 收藏
最近官网上关于无限分类的分享很多,大象也来分享一下我的无限分类,是看了织梦的栏目管理后得写出来的,优点是管理方便,多层级,为此我还写了jquery进行关闭展开分类,缺点是不可重用,希望高手们能给出见解,变成一个可重用的,不过我觉得栏目管理这东西,一个站最多一个,所以重用意义也不大。大象QQ:576272452
织梦的栏目管理非常帅,多级栏目显示上面非常清晰,今天大象仿了个织梦的多级栏目管理,废话不多说,上代码

1、递归类 Typeunit.calss.php
  1. <?
  2. class Typeunit {
  3.     /**
  4.      *  读出所有分类,在类目管理页(list_type)中使用
  5.      *
  6.      * @access    public
  7.      * @param     int   $table  表名
  8.      * @param     int   $topid  当前操作ID
  9.      * @return    string
  10.      */
  11.      public function ListType($table='keshi',$topid=0){
  12.         $Form = M($table);
  13.         $list = $Form->where('topid='.$topid)->order("sort desc,id asc")->select();
  14.         foreach ($list as $k => $v) {
  15.              echo '<tr align="center"  bgcolor="#FBFCE2" height="22" class="fid"><td width="7%"><span class="jia"></span>ID</td><td width="14%">'.$v['id'].'</td><td width="14%">'.$v['name'].'</td><td>操作</td></tr>';
  16.              $this->ListTypeSeed($table,$v['id']);
  17.          } 
  18.     }
  19.        
  20.     /**
  21.      *  读出子分类
  22.      *
  23.      * @access    public
  24.      * @param     int   $table  表名
  25.      * @param     int   $topid  当前操作ID
  26.      * @return    string
  27.      */
  28.     private function ListTypeSeed($table,$topid){
  29.         $Form = M($table);
  30.         $list = $Form->where('topid='.$topid)->order("sort desc,id asc")->select();
  31.         if($list){
  32.             echo '<tr align="center"  bgcolor="#FFFFFF" height="22" class="seed"><td colspan="4"><table width="98%">';
  33.             foreach ($list as $k => $v) {
  34.                  echo '<tr align="center" bgcolor="#FAFAF1" height="22"><td width="7%"><span class="jia"></span>ID</td><td width="14%">'.$v['id'].'</td><td width="14%">'.$v['name'].'</td><td>操作</td></tr>';
  35.                  $this->ListTypeSeed("keshi",$v['id']);
  36.              }
  37.             echo '</table></td></tr>';
  38.         }
  39.     }
  40. }
  41. ?>
2、模板页面 index.html
  1. <script>
  2. $(function(){
  3.     /*
  4.     * 点击展开子类
  5.     *
  6.     */
  7.     $(".jia").click(function(){
  8.         if($(this).parent("td").parent("tr").next(".seed").is(":hidden")){
  9.             $(this).parent("td").parent("tr").next(".seed").show();
  10.             $(this).html("-");
  11.         }else{
  12.             $(this).parent("td").parent("tr").next(".seed").hide();
  13.             $(this).html("+");  
  14.         }
  15.           
  16.     });
  17.     //初始化全部都是-号
  18.     $(".seed").prev(".fid").find("td").find("span.jia").html("-");
  19.       
  20.     /*
  21.     * 点击关闭所有子类
  22.     *
  23.     */
  24.     $("#closeseed").click(function(){
  25.         if($(this).val() == "展开所有子类"){
  26.             $(".seed").show();
  27.             $(this).val("关闭所有子类");
  28.             $.each($(".jia"),function(k,v){
  29.                 if($(this).html()){
  30.                     $(this).html("-");
  31.                 }
  32.             });                     
  33.         }else{
  34.             $(".seed").hide();
  35.             $(this).val("展开所有子类");
  36.             $.each($(".jia"),function(k,v){
  37.                 if($(this).html()){
  38.                     $(this).html("+");
  39.                 }
  40.             });     
  41.         }       
  42.     });
  43. });
  44. </script>
  45. <php>
  46.     $tu = new Typeunit();
  47.     $tu->ListType('keshi',0);
  48. </php>