我工作的一个项目ZF2 ZF2路由器的配置,我需要配置我的一些模块在不同的子域工作的以下情形:处理多个子域
- 我有不同的模块,如API,后端(管理员),应用(核心 模块),博客等。
- 我有多个虚拟主机,它指向同一个 应用程序/ public目录像api.foobar.com,admin.foobar.com
- 我使用的唯一每个模块中的控制器键/别名,如下所示:
...
'controllers' => array(
'invokables' => array(
'home-controller' => 'Application\Controller\IndexController',
),
),
所以,我想基于域改变我的应用程序的行为(主机名/ routeMatch),如果主机看起来像api.foobar.com我的默认控制器应该得到的形成宁静控制器,如果它是一个通用的主页请求,我认证的管理员控制器不应该调用,如果它是移动站点,则将家庭控制器更改为移动控制器,利用不同的布局等...
非工作配置(应用程序/ config/module.config.php):
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'hostname',
'options' => array(
'route' => 'www.foobar.com',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'home-controller',
'action' => 'index'
)
)
),
'api' => array(
'type' => 'hostname',
'options' => array(
'route' => 'api.foobar.com',
'constraints' => array(
'subdomain' => 'api',
),
'defaults' => array(
'__NAMESPACE__' => 'Api\Controller',
'controller' => 'api-controller',
'action' => 'index'
)
)
),
'admin' => array(
'type' => 'hostname',
'options' => array(
'route' => 'admin.foobar.com',
'constraints' => array(
'subdomain' => 'admin',
),
'defaults' => array(
'__NAMESPACE__' => 'Admin\Controller',
'controller' => 'admin-controller',
'action' => 'index'
)
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'__NAMESPACE__' => 'Admin\Controller',
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array()
)
)
)
)
)
)
);
有趣的是,目前这个配置我得到一个404页面没有发现错误api.foobar.com,www.foobar.com和admin.foobar.com在我的开发环境和转储的路线如下:
object(Zend\Mvc\Router\PriorityList)[214]
protected 'routes' =>
array (size=3)
'home' =>
array (size=3)
'route' =>
object(Zend\Mvc\Router\Http\Hostname)[216]
...
'priority' => int 0
'serial' => int 0
'admin' =>
array (size=3)
'route' =>
object(Zend\Mvc\Router\Http\Part)[218]
...
'priority' => int 0
'serial' => int 1
...
'priority' => int 0
'serial' => int 2
protected 'serial' => int 3
protected 'count' => int 3
protected 'sorted' => boolean false
我在应用模块> Module.php> onBootstrap($ E)方法简单地得到这个转储: $路径= $ E-> getApplication() - > getServiceManager->获取('路由器“) - > getRoutes();
问题:
- 什么不对这个CONFIGRATION?
- 为什么我的顶级管理路由列为Zend \ Mvc \ Router \ Http \ Part?
- 我应该将路由定义分隔到本场景的每个模块自己的module.config.php文件中吗?