Zend框架保存并执行POST请求

问题描述:

你好,我有一个网站,如果登录会话超时,我保存这样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

我发现了如何

$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; 

} 

你可以获取和保存模块,控制器,动作和参数,而不是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