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']}
 ?>
}

 

posted @ 2017-06-29 16:41  SYsunyi  阅读(2576)  评论(0编辑  收藏  举报