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