<?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> > </code> </foreach> {$goods['goods_name']} ?> }