2

我想在重定向时设置一个查询参数。我试过这个:

$this->redirect()->toRoute('login/default', array('action' => 'forgotPassword', 'foo' => 'bar'));

它重定向到:

/login/forgotPassword

而不是我想重定向的地方是:

/login/forgotPassword?foo=bar
4

2 回答 2

9

The query parameter belongs to the third parameter of the URL-Methods.

$this->redirect()->toRoute(
    'login/default', 
    array(
        'action' => 'forgotPassword'
    ),
    array( 'query' => array(
        'foo' => 'bar'
    ))
)
于 2013-04-11T09:16:03.823 回答
0

加。

要重定向“访问”或登录,您可以使用表单:

if (!$controller->identity()) {
  $sm = $controller->getServiceLocator();
  $router = $sm->get('router');
  $request = $sm->get('request');

  $routeMatch = $router->match($request);

  $controller->redirect()->toRoute('login', array(), 
        array( 'query' => 
                array('redir' => $routeMatch->getMatchedRouteName() ) ) );
}

网址将是:/login/?redir=current-route

于 2014-10-20T19:09:55.270 回答