2012-02-24 63 views
0

我有以下函數searchAction()和recentsearchAction()。我將我的cookie值存儲爲數組變量$ row。問題是我想在recentsearchAction()方法中獲取我的cookie值。如何得到它。請幫助。我在Zend是全新的。如何將Zend_http_cookie值轉換爲另一個函數或頁面

公共職能searchAction(){

$form=new Application_Form_Search();    

    $this->view->form = $form;   

    if($this->getRequest()->isPost()){ 

     $formData = $this->getRequest()->getPost();    

     if($form->isValid($formData)){ 

      $uname=$form->getValue('uname');     

      $search = new Application_Model_DbTable_Hobbies(); 

      $row=$search->searchHobby($uname);   

      $cookie = new Zend_Http_Cookie('cookiename',$row,'localhost',time() + 7200);   

      echo $cookie->getName(); 

      echo $cookie->getValue(); 

      echo $cookie->getDomain(); 

      echo $cookie->getPath(); 

      echo $cookie->getExpiryTime();         

      $this->view->search=$row;                         

     } 
    } 
}  

public function recentsearchAction() 
{     

}  

回答

0

試試這個:

$session=Zend_Session_Namespace("cookie"); 
$session->setExpirationSeconds(60); 
$session->username; 
$session->email; 

現在,你可以在任何網頁一樣使用該命名空間:

$session=Zend_Session_Namespace("cookie"); 
echo "User Name : ".$session->username; 
echo "Password : ".$session->email; 

它會保存你的數據爲60秒。您可以在幾秒鐘內提供儘可能多的到期時間。

0

我知道ZF留存數據最簡單的方法是將這些數據轉儲到Zend_Session_Namespace,直到你取消它或者將其覆蓋,這將保存數據。 Zend_session將接受字符串,對象和數組。

基本用法:

//save data to namespace named cookie 
$sesion = new Zend_Session_Namespace('cookie'); 
//namespace = cookie, data = cookieData 
$session->cookieData = $cookieData; 

//get data from namespace in another controller or action 
//every time you need to access the namespace you have instantiate Zend_Session_Namespace 
//I usually put a line in init() of each controller assigning it to a protected property 
protected $_sesion = new Zend_Session_Namespace('cookie'); 
//access array or objects parts in session in normal ways 
//assuming session is protected/private property 
echo $this->_session->cookieData->username;//if object 
echo $this->_session->cookieData['email'];//if array, I think 
echo $this->_sesion->cookieData; //if single string 

要取消數據的Zend_Session_Namespace

Zend_Session::namespaceGet('cookie'); 
Zend_Session::namespaceUnset('cookie'); 

我通常投陣列我希望保存爲對象$data = (object)array('data')使接入更加簡單。

+0

** thanxxxxx .... ** – Sky 2012-02-27 05:33:22

相關問題