1

您好,我有一个网站,如果登录会话超时,我会像这样保存请求

 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

4

2 回答 2

0

您可以获取并保存您的模块、控制器、操作和参数而不是 url,然后在您的loginAction

$this->_helper->redirector($action, $controller, $module, array("param1" => $p1,
                                                                "param2" => $p2));
于 2012-07-06T15:35:41.457 回答
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;

}
于 2012-07-06T16:04:45.150 回答