gpt4 book ai didi

module - 如何在 Zend Framework 2 中更改模块的 basePath

转载 作者:行者123 更新时间:2023-12-02 03:36:02 24 4
gpt4 key购买 nike

注意-首先,仔细阅读问题。

我是 ZF2 的新手。现在我正在研究 zend 框架 2.3。我在这个项目中有三个模块,我正在研究 Wamp。

  1. 应用程序 ----------//默认 ZF2 页面。
  2. 专辑------------//ZF2教程示例
  3. Html ----------//我已经创建了

我已经为 Html 模块(最后一个)创建了一个自定义布局。但是有一个basePath的问题。我在这个模块中没有得到正确的页面路径。所以我更改 Html/config/module.config.php 并在 module.config.php 中添加以下脚本

 'view_manager' => array(
'base_path' => 'zend/public/htmlmodule/',
'template_path_stack' => array(
'html' => __DIR__ . '/../view',
),
),

现在,我正在为这个模块获取正确的基本路径。但是现在基本路径会自动更改为另外两个模块,例如相册和应用程序。现在我删除了上面的代码并将这段代码添加到 zend\config\autoload\local.php

view_manager' => array(
'base_path' => 'zend/public/htmlmodule/',
'template_path_stack' => array(
'html' => __DIR__ . '/../view',
),
),

现在这个脚本已经改变了所有模块的路径。

现在,我的问题是,我想为特定模块和布局(可选)更改基本路径,而不是为所有模块更改基本路径,并且想要不同模块的不同基本路径。实际上,如果没有正确的基本路径,您将无法获得正确的图像/css 和 js 文件。

我在这里分享我所有 2 个模块的 module.config.php 文件。

<?php

//Album Module > module.config.php

return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
),

'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),

'view_manager' => array(
'base_path' => 'zend/public/album',
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);

和 HTML 模块的 module.config.php 是:

<?php
return array(
'controllers' => array(
'invokables' => array(
'Html\Controller\Html' => 'Html\Controller\HtmlController',
),
),
'module_layouts' => array(
'Application' => 'layout/layout.phtml',
'Html' => 'layout/custom.phtml',
),

'router' => array(
'routes' => array(
'html' => array(
'type' => 'segment',
'options' => array(
'route' => '/html[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Html\Controller\Html',
'action' => 'index',
),
),
),
),
),

'view_manager' => array(
'base_path' => 'zend/public/htmlmodule/',
'template_path_stack' => array(
'html' => __DIR__ . '/../view',
),
),
);

我想知道,我哪里做错了以及我将如何根据模块获得正确的基本路径。

在此先感谢大家对此问题的贡献。

最佳答案

向每个 View 管理器添加特定的 base_path 键,然后尝试使用 $this->getHelper('basePath')->setBasePath()您生成的 viewModels 只是为了确保。

作为警告,我通过将基本路径设置为树中的“最低点”来完全避免了这个问题,在您的例子中:

'view_manager' => array(
'base_path' => 'zend/public/',
'template_path_stack' => array(
'html' => __DIR__ . '/../view',
),
),

然后在模块特定 View 中添加模块特定路径部分。因此,如果我想访问 public 下相册文件夹中的相册特定 css 或 js 文件,那么在我看来,我将引用基本路径并在路径的其余部分之前简单地添加“/album”。我相信,如果您这样做,您将不会感到头疼。

关于module - 如何在 Zend Framework 2 中更改模块的 basePath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23408321/

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