2015-02-07 79 views
0

我有2個域,我想配置這樣一種方式,每個模塊路由到我的域。如何將Zend Framework 2的每個模塊配置爲每個主機名?

例如

1. domain1 module = domain1.ashwin.com 
2. domain2 module = domain2.ashwin.com 

我已經以下代碼:

module.config.php爲domain1的模塊

return array(
    'router' => array(
     'routes' => array(
      'home' => array(
       'type' => 'Hostname', 
       'options' => array(
        'route' => 'domain1.ashwin.com', 
        'defaults' => array(
         'controller' => 'Domain1\Controller\Index', 
         'action'  => 'index', 
        ), 
       ), 
      ), 
      'home' => array(
       'type' => 'Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         '__NAMESPACE__' => 'Domain1\Controller', 
         'controller' => 'Index', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'default' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '/[:controller[/:action]]', 
          'constraints' => array(
           'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
          ), 
          'defaults' => array(
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
) 

module.config.php爲域2模塊

return array(
    'router' => array(
     'routes' => array(
      'domain2' => array(
       'type' => 'Hostname', 
       'options' => array(
        'route' => 'domain2.ashwin.com', 
        'defaults' => array(
         'controller' => 'Domain2\Controller\Index', 
         'action'  => 'index', 
        ), 
       ), 
      ), 
      'home' => array(
       'type' => 'Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         '__NAMESPACE__' => 'Domain2\Controller', 
         'controller' => 'Index', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'default' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '/[:controller[/:action]]', 
          'constraints' => array(
           'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
          ), 
          'defaults' => array(
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
) 

回答

0

只看你的代碼,你已經宣佈了路線「家」3次。請記住,當Zend 啓動您的模塊時,路線實際上會合併爲一個大數組。

,如果我們把你的module.config.php爲DOMAIN1作爲一個例子 你應該做這樣的事情

'routes' => array(
    'domain1' => array(
     'type' => 'Hostname', 
     'options' => array(
      'route' => 'domain1.ashwin.com', 
      'defaults' => array(
       'controller' => 'Domain1\Controller\Index', 
       'action'  => 'index', 
      ), 
     ), 
     'may_terminate' => true, 
     'child_routes' => array(
      'default' => array(
       'type' => 'Segment', 
       'options' => array(
        'route' => '/[:controller[/:action]]', 
        'constraints' => array(
         'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
        ), 
        'defaults' => array(
         '__NAMESPACE__' => 'Domain1\Controller', 
        ), 
       ), 
      ), 
     ), 
    ), 
), 
相關問題