2012-07-06 116 views
1

你好,我有一個網站,如果登錄會話超時,我保存這樣Zend框架保存並執行POST請求

Abc::saveThisUrl($this->getRequest()); 

public static function saveThisUrl($url) { 
     $lastPg = new Zend_Session_Namespace('history'); 
     $lastPg->url = $url; 
    } 

則成功登錄後,我要執行它

public static function getSavedUrl() { 
     $lastPg = new Zend_Session_Namespace('history'); 
     if(!empty($lastPg->url)) { 
      $path = $lastPg->url; 
      $lastPg->unsetAll(); 
      return $path; 
     } 

     return ''; // Go back to index/index by default; 
    } 
請求

所以在我AbcController.php

public loginAction() 
{ 
...//login succesfull 
//i tried 
$request = Abc::getSavedUrl(); /* @var $request Zend_Controller_Request_Abstract */ 
$this->setRequest($request); 

$this->dispatch($request); 
//or 
$this->run($request->getRequestUri()); 



//also tried 
$front = Zend_Controller_Front::getInstance(); 
        $front->setRequest($request); 
        return $front->dispatch($request); 
} 

機器人h沒有工作。我需要能夠執行互聯網上POST查詢過,許多解決方案只在乎URL

回答

0

我發現瞭如何

$front = Zend_Controller_Front::getInstance(); 
$front->dispatch($request); 

$this->getResponse()->clearBody();//otherwise it sends two time the same output 
return; 
//or die() instead of last 2 lines 

,然後這個

/** 
* Get url from the session, to redirect after successfull login 
*/ 
public static function getSavedUrl() { 
    $lastPg = new Zend_Session_Namespace('history'); 
    if(!empty($lastPg->request)) { 
     $path = $lastPg->request; 

     /* $GLOBALS = $lastPg->GLOBALS; 
     $_SERVER = $lastPg->_SERVER; */ 
     $_GET = $lastPg->_GET; 
     $_POST = $lastPg->_POST; 
     $_FILES = $lastPg->_FILES; 
     $_REQUEST = $lastPg->_REQUEST; 

     $lastPg->unsetAll(); 
     return $path; 
    } 

    return ''; // Go back to index/index by default; 
} 


/** 
* Save url to the session, to redirect after successfull login 
*/ 
public static function saveThisUrl($request) { 
    $lastPg = new Zend_Session_Namespace('history'); 
    $lastPg->unsetAll(); 
    $lastPg->request = $request; 

    /* $lastPg->GLOBALS = $GLOBALS; 
    $lastPg->_SERVER = $_SERVER; */ 
    $lastPg->_GET = $_GET; 
    $lastPg->_POST = $_POST; 
    $lastPg->_FILES = $_FILES; 
    $lastPg->_REQUEST = $_REQUEST; 

} 
0

你可以獲取和保存模塊,控制器,動作和參數,而不是URL,然後把這個在您的loginAction

$this->_helper->redirector($action, $controller, $module, array("param1" => $p1, 
                   "param2" => $p2)); 
+0

$ request包含所有這些,然而我然後檢查像$ this這樣的東西 - > _ request-> isPost()和$ _POST $ _GET沒有恢復,我想我必須用手去做 – max4ever 2012-07-06 15:41:53

+0

i' m不知道你想檢查什麼,但是如果你想獲得請求參數,你可以用這種方式訪問​​它們:$ this - > _ request-> getParam(「param1」,false);' – 2012-07-06 15:48:51