ZF2:传递重定向url作为参数

时间:2014-06-17 06:49:58

标签: routing zend-framework2

我正在尝试实施"登录重定向"在某些情况下,就像我的网站上有一个仅适用于登录用户的页面。

截至目前,当访客用户访问该页面时,访客被重定向到登录页面,我希望用户在登录后重定向到同一页面。

我的登录模块是:http://samsonasik.wordpress.com/2012/10/23/zend-framework-2-create-login-authentication-using-authenticationservice-with-rememberme/ 并已将此代码集成到" application / auth"控制器。

当我使用此网址时: www.qa-staging.com/hemaa/auth/login/redirect/http%3A%2F%2Fgoogle.com
它给了我404错误。

使用时: www.qa-staging.com/hemaa/auth/login/redirect/http://google.com然后路由工作,但我认为这不是一个很好的做法。

控制器:auth
行动:登录
param1:重定向
param2:要重定向的网址

'noModule' => array(  
    'type' => 'Segment',  
        'options' => array(  
            'route'    => '/[:controller][/:action[/:param1[/:param2[/:param3]]]]',  
            'constraints' => array(  
            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',  
            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',  
            'param1'     => '[a-zA-Z0-9_-]*',  
            'param2'     => '(.)+',  
            'param3'     => '(.)+',  
        ),  
        'defaults' => array(  
            '__NAMESPACE__' => 'Application\Controller',  
            'controller'    => 'Index',  
            'action'        => 'index',  
        ),  
    ),  
),  

知道如何实现这一目标吗?

1 个答案:

答案 0 :(得分:0)

我认为您应该考虑使用GET参数。 使用ZF2路由参数来实现这种功能并不是正确的方法。

因此,您的请求将是:

www.qa-staging.com/hemaa/auth/login?redirect=http%3A%2F%2Fgoogle.com

然后在ZF2中你可以得到像这样的GET重定向参数:

$request = $serviceManager->get('Request');
$redirect = $request->getQuery('redirect');

然后您可以稍后使用它来管理您的重定向,例如使用ZF2 redirect plugin