ThinkPHP--面包屑导航


<?php 
/**
 * C层
 * GoodsController.class.php     面包屑导航
 * 获取上一层,上上层的名称
 */
public function mbx($cat_id){
    //获取当前cat_id的该条信息
    $row = D('cat')->find($cat_id);
    $tree[] = $row;//将该条数据放入数组中
    while($row['parent_id']>0){//只要该条数据的parent_id>0
        $row = D('cat_id')->fine($row['parent_id']);
        $tree[] = $row;
    }
    //array_reverse();返回翻转数据的数组
    return array_reverse($tree);//翻转数据
}

//修改对应的显示到模板中的方法
public function goods(){
    //获取该条数据的信息
    $goods_info = D('goods')->find( I ('get.goods_id') );
    //打印该条信息的面包屑导航
    //var_dump($this->mbx($goods_info['cat_id']));
    $this->assign('mbx' , $this->mbx($goods_info['cat_id']));
    $this->assign('goods' , $goods_info);
    $this->play();
}

//显示到模板中
当前位置
<a href="">首页</a>
<foreach name=" mbx " item = " mb ">
<a href=" " >{}</a>
<code> &gt; </code>
</foreach>
{$goods['goods_name']}
 ?>
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM