ZF2 - what will be dispatched if router matches multiple routes?

那年仲夏 提交于 2019-12-05 02:05:01

Since routes attached to the route stack are stored in a priority list, the first matched route will win.

Routes are attached to the main route with a priority setting. Higher priority means the route is checked first. By default, the first attached route is read (if they all have same priority or no priority at all).

'route-catchall' => array(
    'type' => 'regex',
    'options' => array(
        'regex' => '/api/v1/.*',
        'defaults' => array(
            'controller' => 'IndexController',
            'action'     => 'apiCatchAll',
        ),
    ),
    'priority' => -1000,
),
'route-test1' => array(
    'type' => 'literal',
    'options' => array(
        'route' => '/api/v1/route1',
        'defaults' => array(
            'controller' => 'IndexController',
            'action'     => 'apiRoute1',
        ),
    ),
    'priority' => 9001, // it's over 9000!
),

In this example, route-test1 will be matched first because of its high priority.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!