duanqiao2006 2015-02-07 15:38
浏览 54

如何将Zend Framework 2的每个模块配置到每个主机名?

I have 2 domain and I want to configure such a way that each module route to my domain.

e.g.

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

I have following code:

module.config.php for domain1 module

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 for domain2 module

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(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
)
  • 写回答

1条回答 默认 最新

  • donglin7383 2015-02-08 18:38
    关注

    Just looking at your code, you have declared the route 'home' 3 times. Keep in mind that the routes are actually merged together to big array when Zend starts up you modules.

    if we take your module.config.php for domain1 as an example you should do something like this

    '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',
                        ),
                    ),
                ),
            ),
        ),
    ),
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100