douniang3866 2013-01-30 05:53
浏览 14
已采纳

ZF2主机名路由器:将域和tld作为一个参数

I have a route, something like:

            array(
            'type'    => 'Hostname',
            'options' => array(
                'route'    => ':subdomain.:domain.:tld',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            )

What I would like to do is get the domain.tld as one single parameter, because I want to constrain the domain to a list, such as 'application1.com', 'example.org' etc.

I've tried

        array(
            'type'    => 'Hostname',
            'options' => array(
                'route'    => ':subdomain.:domain',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
            ),

Is it possible to handle the domain and tld as a single router param?

  • 写回答

1条回答 默认 最新

  • duanben1324 2013-02-11 13:23
    关注

    I don't think you can do that with that particular router, but you can:

    1) extend/create a new router to act as you want

    2) Move this restriction outside of the codebase.

    3) Using events to check the domain on bootstrap/dispatch and do taken appropriate action

    I would recommend to perform this kind of restriction at a lower level (via apache/web server maybe) rather than in your code. If you want to put it in the code this is probably not the best place to put it.

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

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图