doudaifu6083 2013-12-26 13:15
浏览 36
已采纳

什么是zend框架2中的'may_terminate'?

I am beginner working with Zend. I have seen may_terminate in module route configuration. I don't understand what it is for. According to ZF2 official docs,

the option “may_terminate” hints to the router that no other 
segments will follow it.

Still I don't get the meaning of no other segments will follow it. What is it here? Can anyone please explain it with small example?

  • 写回答

1条回答 默认 最新

  • drazvzi741287 2013-12-26 14:53
    关注

    The may_terminate option will indicate to the router that 'this' route is able to be matched solely on the value of its route; even when it defines child_routes.

    Consider the following example route configuration.

    'router' => [
        'routes' => [
    
            'home' => [
                'type' => 'literal',
                'options' => [
                    'route' => '/home',
                ],
                'may_terminate' => false,
                'child_routes' => [
    
                    'foo' => [
                        'type' => 'literal',
                        'options' => [
                            'route' => '/foo',
                        ],
                    ],
                ],
            ],
        ],
    ],
    

    There is some ambiguity in the above configuration, which only occurs with routes that define children. Do we want to allow our users to match on two routes or just one?

    We could allow matching on just the /home part; which would mean we have two routes both /home and /home/foo or we might only want to allow /home/foo.

    This is where the may_terminate option is used. If we browsed to /home in our browser, when the routing occurs the router cannot regard the home route as a matchable route as may_terminate = false. In ZF2 terminology the router cannot "terminate" at this route and continues on searching for a match into the child_routes, which will fail and a 404 error will be raised.

    So by modifying the value of the may_terminate option in the above example, we can change the routes that can be matched on.

    may_terminate = true

    • home
    • home/foo

    may_terminate = false

    • home/foo
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行