2014-01-08 46 views
0

如何在zend会话中添加产品?我收到的产品为数组在zend会话中存储产品

我尝试这一点,但不工作

A和如何ü采取其他操作本次会议...

日Thnx很多

public function incartAction(){ 
    $this->_helper->_layout->disableLayout();   
    $id = $this->_getParam("id"); 
    $name= $this->_getParam("name"); 
    $price= $this->getParam("price"); 
    $img = $this->_getParam("img"); 
    $qty = $this->_getParam("qty"); 

    $produs = array(
     "id"=>$id, 
     "name"=>$name, 
     "price"=>$price, 
     "img"=>$img, 
     "qty"=>$qty 
    );   
    $produs_model = new Application_Model_DbTable_Produs; 
    $produs_model->updateProdusById($id, $qty); 

    $cart = new Zend_Session_Namespace("products"); 
    $cart->products->$name= $product; 

    $this->view->assign("cart", $cart);   
} 

回答

1

好你个做错了,你也有可变名称的错误,

这里是你如何做到这一点,

先在一些控制器定义它,

public function incartAction(){ 
    $product = array(
      "id"=>$id, 
      "name"=>$name, 
      "price"=>$price, 
      "img"=>$img, 
      "qty"=>$qty 
      ); 


//add it to session variable [in same controller] 

    $cart = new Zend_Session_Namespace("products"); 
    $cart->product= $product; 
} 

现在在另一个控制器使用它,

public function outcartAction(){ 
    $cart = new Zend_Session_Namespace("products"); 
    $product= $cart->product; 
    print_r($product); 
} 
+0

日Thnx家伙......我昨晚纠正我的错误,现在所有的罚款:) –

+0

高兴如果你觉得有帮助,你可以[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。 –