Blogger Information
Blog 16
fans 0
comment 0
visits 18220
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
ThinkPHP3.2.3中如何显示二级栏目
忧郁之子的博客
Original
789 people have browsed it

一、控制器代码如下:

public function index()    
{
     $cate = D('cate');//实例化数据表cate
  /* 方法一*/
     $where['parent_id']=0;
     $cates = $cate->where($where)->select();
     /* 方法二
  $cates = $cate->where(array('parent_id'=>'0'))->select(); 
  */
       $this->assign('cates',$cates);//分配到模板中
        $this->display();   
}

二、在Application/common/common目录下的function.php写一个get_cate_children()函数通过获取父ID来查询所有子栏目函数代码如下:

/传入参数为当前栏目的id(即所要调用的子栏目的paren_id)

function get_cate_children($cate_id)
{
    $cate = D('cate');
    //当子栏目的parent_id等于传入的栏目id时,查找出所有子栏目
    $cates = $cate->where(array('parent_id'=>$cate_id))->select();
    return $cates;//返回值
}

三、模板中显示顶级栏目和二级栏目:

<!--顶级栏目-->
<volist name="cates" id="vo">
    <li class="mnav">
        <a href="#" class="">
            <p>{$vo.cate_name}</p>
            <p class="en">{$vo.cate_ename}</p>
        </a>
        <ul class="smenu">
            <!--子栏目调用get_cate_children()函数-->
            <volist name=":get_cate_children($vo['cate_id'])" id="vo">
            <li>
               <a href="#">{$vo.cate_name}</a>
            </li>
            </volist>
        </ul></li>
</volist>

 

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post