ThinkPHP--瀏覽曆史

來源:互聯網
上載者:User

標籤:擷取   var_dump   調用   注意   var   this   個數   tor   寫入   

<?php /** * session.php     瀏覽曆史 * 1)需要在goods()查詢出來的資訊做判斷。查詢出來有資訊時才能進行寫入session。否則不寫入 * 2)寫對應的方法history * 3)在對應模板中顯示出曆史瀏覽 *///對於goods()查詢出來的資訊做判斷public function goods(){    $goods_info = D( ‘ goods ‘ )->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();}//寫入到對應的模板中 ?>

 

ThinkPHP--瀏覽曆史

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.