tp 浏览信息!!!!!!!!!
//放在session 不能放在变量里记录 因为 变量会销毁
----------------------------------
每次浏览一条商品 就把 session 信息存起来
应该在 goods 方法下 存起来
public function goods(){
$goods = D('Goods');
$g = $goods->cache(true)->find(I('get.goods_id'));
if(empty($g)) {
$this->redirect('/');
}
$this->assign('g' , $g);
$goods = D('Goods');
$g = $goods->cache(true)->find(I('get.goods_id'));
if(empty($g)) {
$this->redirect('/');
}
$this->assign('g' , $g);
if(IS_POST) {
$comm = M('Comment');
$comm->create(); // 先收取POST,收到content,email
$comm->user_id = cookie('user_id') ? cookie('user_id') : 0;
$comm->pubtime = time();
$comm->goods_id = $goods->goods_id;
//print_r($g);exit;
$comm->add();
}
$comm = M('Comment');
$comm->create(); // 先收取POST,收到content,email
$comm->user_id = cookie('user_id') ? cookie('user_id') : 0;
$comm->pubtime = time();
$comm->goods_id = $goods->goods_id;
//print_r($g);exit;
$comm->add();
}
// 取商品的评论
//$comm->where('goods_id='.$goods->goods_id)->order('pubtime desc');
$this->assign('comm' , $goods->relationGet('Comment'));
//$comm->where('goods_id='.$goods->goods_id)->order('pubtime desc');
$this->assign('comm' , $goods->relationGet('Comment'));
$cat = D('Cat');
$this->assign('cats' , $cat->getMbx($g['cat_id']));
$this->assign('cats' , $cat->getMbx($g['cat_id']));
-------------- -------------- -----
------ // 把商品信息写入历史记录(session) ----------------
$this->history($g);
------------- ------------------
$this->display();
------ // 把商品信息写入历史记录(session) ----------------
$this->history($g);
------------- ------------------
$this->display();
--------------------------------------------------------------------------------
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
————————————————————————————————————————————————————————————————————————————————
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
————————————————————————————————————————————————————————————————————————————————
如果浏览信息 应该先判断
如果没有那么 造一个空的session history 字段
如果有 那么 向里边添加
如果有 那么 向里边添加
public function history($g){
$history = session('?history');
if(isset($history)){
$history= array();
}else{
$row = array();
$row['goods_name']= $g['goods_name'];
$row['shop_price']= $g['shop_price'];
$row['thumb_img']= $g['thumb_img'];
$history[$g['goods_id']]=$row;
}
}
}
}
if(count($history) > 6) {
$key = key($history); // 第1个单元的键
unset($history[$key]);
}
$key = key($history); // 第1个单元的键
unset($history[$key]);
}
session('history' , $history);
}
}
public function history($g) {
$history = session('history');
$history = session('history');
if(empty($history)) {
$history = array();
}
$history = array();
}
if(isset($history[$g['goods_id']])) {
unset($history[$g['goods_id']]);
}
unset($history[$g['goods_id']]);
}
$row = array();
//$g 来自于 浏览商品时候的img
$row['thumb_img'] = $g['thumb_img'];
$row['goods_name'] = $g['goods_name'];
$row['shop_price'] = $g['shop_price'];
$row['thumb_img'] = $g['thumb_img'];
$row['goods_name'] = $g['goods_name'];
$row['shop_price'] = $g['shop_price'];
$history[$g['goods_id']] = $row;
--