我是Zend Framework 2的新手。我几天前开始使用它。过去三天我一直在为模块结构而努力。我想有2个模块:主要和管理员。Zend Framework 2模块
我有application.config.php文件: “管理员” 模块的
return array(
'modules' => array(
'main', 'Administrator',
),
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
),
);
module.config.php:
return array(
'router' => array(
'routes' => array(
'Administrator' => array(
'type' => 'Literal',
'options' => array(
'route' => '/administrator',
'defaults' => array(
'__NAMESPACE__' => 'Administrator\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(
),
),
),
),
),
),
),
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'controllers' => array(
'invokables' => array(
'Administrator\Controller\Index' => 'Administrator\Controller\IndexController',
'Administrator\Controller\Blogs' => 'Administrator\Controller\BlogsController',
'Administrator\Controller\Design' => 'Administrator\Controller\DesignController',
'Administrator\Controller\FAQ' => 'Administrator\Controller\FAQController',
'Administrator\Controller\Interests' => 'Administrator\Controller\InterestsController',
'Administrator\Controller\Main' => 'Administrator\Controller\MainController',
'Administrator\Controller\Pages' => 'Administrator\Controller\PagesController',
'Administrator\Controller\RSS' => 'Administrator\Controller\RSSController',
'Administrator\Controller\Users' => 'Administrator\Controller\UsersController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'administ/index/index' => __DIR__ . '/../view/administrator/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
和module.config.php的 “主”模块:
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'__NAMESPACE__' => 'Main\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
),
'Main' => array(
'type' => 'Literal',
'options' => array(
'route' => '/main',
'defaults' => array(
'__NAMESPACE__' => 'Main\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(
),
),
),
),
),
),
),
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'controllers' => array(
'invokables' => array(
'Main\Controller\Index' => 'Main\Controller\IndexController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'main/index/index' => __DIR__ . '/../view/main/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
这是我的文件结构:
我编辑这篇文章有点。现在看来,问题现在只有布局。无论我打开什么,它都会显示“管理员”模块的布局和正确的页面内容(或错误消息,取决于控制器/模块/操作是否存在)。所以这个问题似乎只与布局有关。
P.S.当我在application.config.php首先列出管理员模块:
'modules' => array(
'Administrator', 'Main'
),
它仅示出了“主”模块布局,反之亦然 - 当“主”是模块阵列中的第一个元素 - 管理员布局无处不在。
https://github.com/EvanDotPro/EdpModuleLayouts – Xerkus
为模块命名惯例是使用你的前缀和名字组合。例如EdpModuleLayouts:Edp是前缀,ModuleLayouts是名称 – Xerkus