那么 - 如果我有一个可能与许多路线相匹配的网址...会赢得哪条路线怎么办?将分派哪些行动?
它是否简单 - 首先定义 - 首先发送?
这是路线,例如:
'route-catchall' => array(
'type' => 'regex',
'options' => array(
'regex' => '/api/v1/.*',
'defaults' => array(
'controller' => 'IndexController',
'action' => 'apiCatchAll',
),
),
),
'route-test1' => array(
'type' => 'literal',
'options' => array(
'route' => '/api/v1/route1',
'defaults' => array(
'controller' => 'IndexController',
'action' => 'apiRoute1',
),
),
),
Run Code Online (Sandbox Code Playgroud)
这个网址example.com/api/v1/route1会被路由到apiRoute1或 apiCatchAll?
Ocr*_*ius 18
由于附加到路由堆栈的路由存储在优先级列表中,因此第一个匹配的路由将获胜.
路由连接到与主路priority设置.优先级越高意味着首先检查路由.默认情况下,读取第一个附加路由(如果它们都具有相同的优先级或根本没有优先级).
'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!
),
Run Code Online (Sandbox Code Playgroud)
在此示例中,route-test1由于其高优先级,将首先匹配.