find( ' get.goods_id ' ); if($goods_info){ //若获取该条信息成功 //调用history()方法 $this->history($goods_info); //var_dump(session('history')); } $this->assign( ' mbx ' , $this->mbx($goods_info['cat_id'])); $this->assign( ' goods ' , $goods_info); $this->display();}//写对应的方法history()public function history($info){ //判断session里面有没有历史,若没有给空,有,将session赋给$row $row = session( ' ?history ' )?session('history'):array(); //将查询过的数据放在一个数组中,查询出来对应的商品的id新建一个数组,形成二维数组 $g = array(); $g['goods_name'] = $info['goods_name']; $g['shop_price'] = $info['shop_price']; $g['goods_id'] = $info['goods_id']; $row[$info[ ' goods_id ' ]] = $g; //若数据大于7条,则删除第一条 if(count($row)>5){ //count记录总条数 $key = key($row);//key()从数组中返回当前指针所在的位置的键名 unset($row[$key]); } session('history' , $row);}//cat页面的浏览历史,注意浏览顺序。翻转函数array_reverse()public function cat(){ $cat_id = I('get.cat_id'); $this->assign('his' , array_reverse(session('history'))); $cats = D('gods')->filed(........); $this->assign('cat_goods' , $cats); $this->display();}//写入到对应的模板中 ?>