在 ZF3 中,我想从路由中获取默认参数。我在控制器中以这种方式获取参数:
$params = $this->params()->fromRoute('crud');
我的网址如下所示:
1: somedomain/admin/color/add
2: somedomain/admin/color
1)我进入add
我的$params
变量。
在2)我得到null
但我期待默认(在这种情况下view
)
我认为这是路由器配置错误的问题。
'admin' => [
'type' => Segment::class,
'options' => [
'route' => '/admin/:action',
'defaults' => [
'controller' => Controller\AdminController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'color' => [
'type' => Segment::class,
'options' => [
'route' => '/:crud',
'constraints' => [
'crud' => 'add|edit|delete|view',
],
'defaults' => [
'controller' => Controller\AdminController::class,
'crud' => 'view',
],
],
],
],
],