ZF2段子路由不起作用

时间:2014-01-23 10:00:41

标签: php routing zend-framework2 zend-route zend-router

我想要实现的目标:

domain.com/user                    = UserController::index
domain.com/user/profile            = UserController::profile
domain.com/user/profile/9          = UserController::profile (with query param id=9)
domain.com/user/profile/9/edit     = UserController::editProfile (with query param id=9)

所以我有以下路线:

'user' => array(
    'type'    => 'Segment',
    'options' => array(
        'route'    => '/user',
        'defaults' => array(
            '__NAMESPACE__' => 'YrmUser\Controller',
            'controller'    => 'User',
            'action'        => 'index',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'profile' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/profile[/:id]',
                'defaults' => array(
                    'action' => 'profile',
                ),
                'constraints' => array(
                    'id' => '[0-9]*'
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'edit' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/edit',
                        'defaults' => array(
                            'action' => 'editProfile',
                        ),
                    ),
                    'may_terminate' => true
                ),
            )
        ),
    )
)

除了查询参数ID永远不会获得值之外,它还有用。 谁能告诉我我做错了什么,我猜它的东西很愚蠢......

提前致谢,

YRM

1 个答案:

答案 0 :(得分:1)

适合我。

我在行动中var_dumped $this->params ('id')得到了这个:

/user
null

/user/profile
null

/user/profile/99
string '99' (length=2)

/user/profile/99/edit
string '99' (length=2)