문제

Is it possible to create a router in Zend Framework that can match hostnames using a wildcard or regular expressions (no matter how many parts are in the hostname)?

I can create a route that matches based on a hostname

   $externalHostname = new Zend_Controller_Router_Route_Hostname(
        'ext.mysite.com', array(
            'module'=> 'external',
    ));

But what if I wanted to achieve something like this:

   $externalHostname = new Zend_Controller_Router_Route_Hostname(
        'ext.*', array(
            'module'=> 'external',
    ));

where any hostname that starts with "ext." gets routed to the "external" module, independent of how many subdomain levels the hostname has, so

  • ext.mysite.com
  • ext.test.mysite.com

would both match.

How can that be achieved?

도움이 되었습니까?

해결책

You can not achieve this by Zend_Controller_Router_Route_Hostname. If you were intended to match only a limited number of subdomain levels (let's say 2-4), it could have worked. In this case you would add several Hostname routes for each case.

But unlimited -- I don't think so.

다른 팁

What does Zend Router do ?

Answer : It basically sets and tells the Front Controller what is the current module/controller/action. And then Front controller tells Zend Dispatcher go to moduleFolder/controllerFolder and executes actionMethod.

Now you can check your above condition and set the router manually.

Now the question is where you should check and set this router?

One of the solution is :- in public/index.php file you can register it like a plugin $frontController->registerPlugin("my_router") and my_router should extends "Zend_Controller_Plugin_Abstract". Inside this my_router class constructor you can set your own router.

I would you say, just check Zend Framework basic flow ( What happens inside zend framework when make a request? )

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top