Routing ZF2如何将URL段作为操作参数传递

Routing ZF2如何将URL段作为操作参数传递,routing,zend-framework2,Routing,Zend Framework2,我得到了如下网址: 我想将URL的两个部分(4442323222344和HLKKLKH)映射为我的重定向操作的参数,因此$messageId是“4442323222344”,而$hash是“HLKKLKH” 这是路线: 'router' => array( 'routes' => array( .... 'redirect' => array( 'type' =&g

我得到了如下网址:

我想将URL的两个部分(4442323222344和HLKKLKH)映射为我的重定向操作的参数,因此$messageId是“4442323222344”,而$hash是“HLKKLKH

这是路线:

    'router' => array(
        'routes' => array(
             ....
            'redirect' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/r',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'redirect',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/:messageId/:hash',
                            'constraints' => array(
                                'messageId' => '[a-zA-Z0-9]+',
                                'hash'     => '[a-zA-Z0-9]+',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
            ...
        ),
   ),
这就是行动:

class IndexController extends AbstractActionController implements ConfigAwareInterface
{
    ...
    public function redirectAction($messageId,$hash)
    {
      ...
      myFunc($messageId,$hash);
      ...
    }
    ...
}
我知道我可以通过以下方式获得这些片段:

$_messageId = $this->params()->fromRoute('messageId');
$_hash = $this->params()->fromRoute('hash');

但我发现通过函数params传递变量更“干净”。

目前不可能这样做。这是对ZF3的一个改进(它不会很快发布,所以不用担心),但在ZF2中,您不会看到此功能发布


您现在需要使用-plugin

这样做目前是不可能的。这是对ZF3的一个改进(它不会很快发布,所以不用担心),但在ZF2中,您不会看到此功能发布


你现在需要继续使用-plugin

这真的出乎意料,但我能活下来:)这真的出乎意料,但我能活下来:)