【问题标题】:Storing products in session with zend使用 zend 在会话中存储产品
【发布时间】:2014-01-08 19:21:56
【问题描述】:

您如何在与zend 的会话中添加产品?我以数组的形式接收产品

我试试这个,但是不行

a 以及你如何在另一个动作中进行此会话...

非常感谢

 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);        
}

【问题讨论】:

    标签: php session zend-framework namespaces


    【解决方案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);
    }
    

    【讨论】:

    • thnx 老兄......我昨晚纠正了我的错误,现在一切都很好:)
    • 很高兴有帮助,如果您觉得有帮助,可以accept answer
    猜你喜欢
    • 2014-06-29
    • 1970-01-01
    • 2011-08-23
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多