Zend 2框架路由

时间:2013-06-04 14:37:21

标签: zend-framework zend-framework2 zend-route zend-router

我正在努力解决这个问题,无法克服它。

我想要实现的是这样的路线:/ rolepermission [/:roleid] / permissions [/:permissionid] [/ action /:action]

目前我想出了类似的东西:

        'rolepermission' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/rolepermission',
                'constraints' => array(),
                'defaults' => array(
                    'controller' => 'My\Controller\RolePermission',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'rolepermissionroleid' => array(
                    'type' => 'segment',
                    'options' => array(
                        'route' => '/[:roleid]',
                        'constraints' => array(
                            'roleid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                            'action' => 'detail',
                        ),
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'rolepermissionpermissions' => array(
                            'type' => 'literal',
                            'options' => array(
                                'route' => '/permissions',
                                'constraints' => array(),
                                'defaults' => array(
                                    'action' => 'index'
                                ),
                            ),
                            'may_terminate' => true,
                            'child_routes' => array(
                                'rolepermissionpermissionid' => array(
                                    'type' => 'segment',
                                    'options' => array(
                                        'route' => '/[:permissionid]',
                                        'constraints' => array(
                                            'permissionid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                        ),
                                        'defaults' => array(
                                        ),
                                    ),
                                    'may_terminate' => true,
                                    'child_routes' => array(
                                        'rolepermissionaction' => array(
                                            'type' => 'segment',
                                            'options' => array(
                                                'route' => '/action/[:action]',
                                                'constraints' => array(
                                                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                ),
                                                'defaults' => array(
                                                    'action' => 'index'
                                                ),
                                            ),
                                            'may_terminate' => false,
                                            'child_routes' => array(),
                                        ),
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),

当路由到/ rolepermission / permissions时,我不断地将'permissions'替换为:roleid。由于没有传递一个角色,我期待在这里没有什么可以替代的。我做错了什么?

提前致谢, 欢呼声

1 个答案:

答案 0 :(得分:1)

通过调整'rolepermissionpermissions'子路由来暂时解决问题如下:

'rolepermission' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/rolepermission',
                'constraints' => array(),
                'defaults' => array(
                    'controller' => 'My\Controller\RolePermission',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'rolepermissionroleid' => array(
                    'type' => 'segment',
                    'options' => array(
                        'route' => '/:roleid',
                        'constraints' => array(
                            'roleid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                            'action' => 'detail'
                        ),
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'rolepermissionpermissionid' => array(
                            'type' => 'segment',
                            'options' => array(
                                'route' => '[/permission/:permissionid]',
                                'constraints' => array(
                                    'permissionid' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                ),
                                'defaults' => array(
                                    'action' => 'detail',
                                ),
                            ),
                            'may_terminate' => true,
                            'child_routes' => array(
                                'rolepermissionaction' => array(
                                    'type' => 'segment',
                                    'options' => array(
                                        'route' => '/action/:action',
                                        'constraints' => array(
                                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                        ),
                                        'defaults' => array(
                                            'action' => 'detail'
                                        ),
                                    ),
                                    'may_terminate' => true,
                                    'child_routes' => array(),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),

虽然它确实不是最佳解决方案,但现在可以使用。