Php 从重定向请求获取参数

Php 从重定向请求获取参数,php,zend-framework2,Php,Zend Framework2,我正在尝试使用以下代码重定向用户: return $this->redirect()->toRoute('application', array( 'controller' => 'Index', 'action' => 'connexion', null, array('e' => 'n'),

我正在尝试使用以下代码重定向用户:

return $this->redirect()->toRoute('application', array(
                    'controller' => 'Index',
                    'action' => 'connexion',
                    null,
                    array('e' => 'n'),
                ));
并通过以下方式从布局中获取e参数的内容:

$_REQUEST['e']
但这样做我什么也抓不到。请问我怎样才能拿到它


提前谢谢

视图中匹配的路由参数:

$this->getHelperPluginManager()
    ->getServiceLocator()
    ->get('Application')
    ->getMvcEvent()
    ->getRouteMatch()
    ->getParams()
视图中的请求查询/发布:

$this->getHelperPluginManager()
->getServiceLocator()
->get('Request')
->getQuery()->toArray()

$this->getHelperPluginManager()
->getServiceLocator()
->get('Request')
->getPost()->toArray()

正如你在问题的评论中提到的,方法是:$this->params->fromRoute;由@Notuser提及。在向视图传递参数时,将在一个简单的示例中使用它

class ExampleController extends AbstractActionController
{

    public function rerouteAction()
    {
        // Notice that 'param' is a route within our route.config.php and in there we
        // define the controller and action, so we do not need to set the controller
        // and action in the redirect. So param now points to paramAction of ExampleController.
        return $this->redirect()->toRoute('param', array('e' => 'n'));
    }

    public function paramAction()
    {
        // Leaving fromRoute() blank will return all params!
        $params = $this->params()->fromRoute();
        $e = $params['e'];
        return array('e' => $e);
    }
}
因此,在您的view.phtml中,您现在可以轻松地执行以下操作:n

上述示例的route.config如下所示:

return array(
    'router' => array(
        'routes' => array(
            'reroute' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => 'reroute',
                    'defaults' => array(
                        'controller' => 'Application\Controller\ExampleController',
                        'action' => 'reroute'
                    )
                )
            ),
            'param' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => 'param',
                    'defaults' => array(
                        'controller' => 'Application\Controller\ExampleController',
                        'action' => 'param'
                    )
                )
            )
        )
    )
);

$this->params->fromRoute'e',0;在里面controller@Notuser,我正在尝试从视图处理此问题。您可以从控制器发送它,也可以创建自己的视图helper@Marius.C,我正在将参数从控制器发送到视图。@Marius.C,它也不起作用。我刚刚使用dieprint$this->e;从视图中测试了这一点;。我已经测试了$_REQUEST[e]、$this->e和$e。这不起作用,您以前需要什么配置吗?