sergiohermes/zf3-mvc-layout-manager

ZF3模块布局管理器。

2.0.0 2017-12-07 14:07 UTC

This package is auto-updated.

Last update: 2024-09-29 05:14:43 UTC


README

ZF3模块布局管理器。

如果您有一个模块化应用,每个模块可以拥有不同的布局。

通常 登录仪表板 应该有不同和独立的 CSS 和 JavaScript。

目前,这不在zendframework中默认支持。

此包将允许您为不同的模块定义不同的布局。

安装

在您的终端中执行以下命令

composer require sergiohermes/zf3-mvc-layout-manager

添加 **config/modules.config.php**

"modules" => [
    "ZF3LayoutManager"
],

使用方法

每个模块默认都存在一个包含此 view_manager 配置的 module.config.php 文件。

'view_manager' => [
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
    'doctype'                  => 'HTML5',
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index',
    'template_map' => [
        'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ],
    'template_path_stack' => [
        __DIR__ . '/../view',
    ],
],

此模块不强制您通过“监听器”跳出默认模式,该监听器是 Layout.php 文件中的 manageLayoutForModule 事件。

因此,如果您需要更改 template_map,请随意输入所需值,但请注意,键也可以更改,但这会产生不适当的维护工作。因此,尽可能重用。

配置

Zend Framework具有显式配置,即如果您不配置值,它将定义框架的标准属性。

因此,让我们配置 :neckbeard:

在项目的全局配置中创建一个文件。通常位于 config/autoload 中,命名为 layout.global.php,或者复制 config/zf3-mvc-layout-manager.php.dist 文件。

假设我的应用程序中有3个模块 **Admin, Dashboard 和 Login**,配置将如下所示

全局配置

'module_layouts' => [
    'Admin' => 'layout/admin-layout',
    'Dashboard' => 'layout/dashboard-layout',
    'Login' => 'layout/login-layout',

],

本地配置

模块 ADMIN

每个模块默认都存在一个包含此 view_manager 配置的 module.config.php 文件。

'view_manager' => [
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
    'doctype'                  => 'HTML5',
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index',
    'template_map' => [
        //'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'layout/admin-layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ],
    'template_path_stack' => [
        __DIR__ . '/../view',
    ],
],

模块 Dashboard

每个模块默认都存在一个包含此 view_manager 配置的 module.config.php 文件。

'view_manager' => [
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
    'doctype'                  => 'HTML5',
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index',
    'template_map' => [
        //'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'layout/dashboard-layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ],
    'template_path_stack' => [
        __DIR__ . '/../view',
    ],
],

模块 Login

每个模块默认都存在一个包含此 view_manager 配置的 module.config.php 文件。

'view_manager' => [
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
    'doctype'                  => 'HTML5',
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index',
    'template_map' => [
        //'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'layout/login-layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ],
    'template_path_stack' => [
        __DIR__ . '/../view',
    ],
],

请注意,您可以使用 layout/layout,实际上我就是这样做的,但我相信对于教程的标题,您会更好地理解魔法是如何工作的。

圣诞快乐,新年快乐!