gpt4 book ai didi

frameworks - Zend Framework 2 模块

转载 作者:行者123 更新时间:2023-12-03 11:17:01 25 4
gpt4 key购买 nike

我是Zend Framework 2的新手,几天前开始使用它。在过去的三天里,我一直在为模块结构而苦苦挣扎。我想要 2 个模块:main 和 administrator。

我有 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',
),
),
);

这是我的文件结构: structure

我对这篇文章做了一些编辑。现在,问题似乎只出在布局上。无论我打开什么,它都会显示“管理员”模块的布局和正确的页面内容(或错误消息,这取决于 Controller /模块/操作是否存在)。所以问题似乎只出在布局上。

附言当我首先在 application.config.php 中列出管理员模块时:

'modules' => array(
'Administrator', 'Main'
),

它只显示“主要”模块布局,反之亦然 - 当“主要”是模块数组中的第一个元素时 - 管理员布局随处显示。

最佳答案

'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(

// The following key will be overriden, and the last loaded module config
// is the one used, just comment it (for both modules config) the default
// behavior will pick-up the default/conventional layout.

//'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',
),
),

关于frameworks - Zend Framework 2 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14626224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com