简体   繁体   中英

ZF2 Hostname router : get domain and tld as one param

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM