Zend Framework 3:如何通过url路由到特定控制器

时间:2018-05-10 17:37:45

标签: routes zend-framework3

在我的模块的module.config.php中,我有类似的东西:

'controllers' => [
    'factories' => [
        Controller\MainappController::class => 
                Controller\Factory\MainappControllerFactory::class,
        //...
        Controller\VoucherController::class => 
                Controller\Factory\VoucherControllerFactory::class,
        //...
    ],
],    
'router' => [
    'routes' => [
        'mainapp' => [
            'type'    => Segment::class,
            'options' => [
                'route' => '/mainapp[/:action[/:first_id][/:second_id]]',
                'constraints' => [
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ],
                'defaults' => [
                    'controller' => Controller\MainappController::class,
                    'action'     => 'index',
                ],
            ],
        ],
        'voucher' => [
            'type'    => Segment::class,
            'options' => [
                'route' => '/voucher[/:action[/:first_id][/:second_id]]',
                'constraints' => [
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ],
                'defaults' => [
                    'controller' => Controller\VoucherController::class,
                    'action'     => 'index',
                ],


            ],
        ],
    ],
],

凭证是同一模块中的新控制器

我可以转到public/mainapp

但是当我尝试public/voucher

我有错误

  

发现404错误页面未找到。

路由无法匹配请求的网址。

请告诉我这个配置有什么问题。

0 个答案:

没有答案