zend-framework2 - ZF2-如果路由器匹配多个路由,将调度什么?

标签 zend-framework2

所以-如果我的网址可能与许多路线相匹配,哪条路线会获胜呢?将采取哪个行动?

它是简单的-首先定义-首先 dispatch 吗?

例如,以下路线:

'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',
        ),
    ),
),

该网址example.com/api/v1/route1是否会路由到apiRoute1apiCatchAll

最佳答案

由于附加到路由堆栈的路由存储在priority list中,因此第一个匹配的路由将获胜。

路线通过 priority setting附加到主路线。较高的优先级意味着首先检查路由。默认情况下,读取第一个附加路由(如果它们都具有相同的优先级或根本没有优先级)。

'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!
),

在此示例中,由于route-test1具有高优先级,因此将首先对其进行匹配。

关于zend-framework2 - ZF2-如果路由器匹配多个路由,将调度什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15122366/

相关文章:

mysql - 连接查询结果显示出现问题

php - HTML2PDF - fopen() 无法在第 6168 行打开流 : Permission denied in/html2pdf/_tcpdf_5. 0.002/tcpdf.php

database - ZF2 在 View 助手中使用数据库表模型

zend-framework2 - ZF2 : When would you use autoload_classmap. php

symfony - Zend Framework 2 和 Symfony 2 的主要区别

mysql - 在 Zend 框架 2 的子查询中使用 limit 和 offset

zend-framework2 - zend2 框架中帧错误的预期数组

macos - 在 Mac OS X for Zend Framework 2 上为 Apache 2 安装和配置 mod_rewrite

email - ZF2 : Using Zend\View to render emails

html - 在 View 脚本中使用 css DIV 区域