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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?