我试图实现的目标:
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 永远不会得到值的事实。谁能告诉我我做错了什么,我猜它是愚蠢的简单...
提前致谢,
年限