你好,我有一个网站,如果登录会话超时我就像这样保存请求
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);
}
两个都没用。我需要能够执行 POST查询,互联网上的许多解决方案只关心URL
答案 0 :(得分:0)
您可以获取并保存模块,控制器,操作和参数而不是网址,然后在loginAction
中调用它:
$this->_helper->redirector($action, $controller, $module, array("param1" => $p1,
"param2" => $p2));
答案 1 :(得分: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;
}