首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改默认模块?

如何更改默认模块?
EN

Stack Overflow用户
提问于 2017-03-19 00:12:18
回答 1查看 1.1K关注 0票数 0

我已经安装了ZF3,默认情况下模块是“应用程序”。我想改变这个模块在默认情况下由其他。我怎么能这么做?

编辑I:我做了一些更改,但它不起作用:

/config/modules.config.php

代码语言:javascript
复制
return [
    'Zend\Router',
    'Zend\Validator',
    'Test',
];

/module/Test/config/module.config.php

代码语言:javascript
复制
<?php
namespace Test;

use Zend\ServiceManager\Factory\InvokableFactory;

return [
    'controllers' => [
        'factories' => [
            Controller\IndexController::class => InvokableFactory::class,
        ],
    ],
    'router' => [
        'routes' => [
            'home' => [
                'type'    => "Literal",
                'options' => [
                    // Change this to something specific to your module
                    'route'    => '/',
                    'defaults' => [
                        'controller'    => Controller\IndexController::class,
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    // You can place additional routes that match under the
                    // route defined above here.
                ],
            ],
        ],
    ],
    'view_manager' => [
        'template_path_stack' => [
            'Test' => __DIR__ . '/../view',
        ],
    ],
];

当我尝试访问http://localhost时,我得到的结果是:

致命错误: Uncaught \View\Exception\RuntimeException: Zend\View\Renderer\PhpRenderer:: render :无法呈现模板"error";resolver无法解析到C:\Apache24\htdocs\shop\vendor\zendframework\zend-view\src\Renderer\PhpRenderer.php:494堆栈跟踪中的文件:#0 C:\Apache24\htdocs\shop\vendor\zendframework\zend-view\src\View.php(207):Zend\View\Renderer\PhpRenderer->render() 1 C:\Apache24\htdocs\shop\vendor\zendframework\zend-view\src\View.php(236):Zend\View\View->呈现(对象(Zend\View\Model\ViewModel) #2 C:\Apache24\htdocs\shop\vendor\zendframework\zend-view\src\View.php(200):Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel)) #3 C:\Apache24\htdocs\shop\vendor\zendframework\zend-mvc\src\View\Http\DefaultRenderingStrategy.php(105):Zend\View\View->render(Object(Zend\View\Model\ViewModel)) #4 C:\Apache24\htdocs\shop\vendor\zendframework\zend-eventmanager\src\EventManager.php(322):Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent)) 5 C:\Apache24 24\htdocs\shop\ve在第494行的C:\Apache24\htdocs\shop\vendor\zendframework\zend-view\src\Renderer\PhpRenderer.php中

编辑II (固定):

/config/modules.config.php

代码语言:javascript
复制
return [
    'Zend\Router',
    'Zend\Validator',
    'Test',
];

/module/Test/config/module.config.php

代码语言:javascript
复制
<?php
namespace Test;

use Zend\ServiceManager\Factory\InvokableFactory;

return [
    'controllers' => [
        'factories' => [
            Controller\IndexController::class => InvokableFactory::class,
        ],
    ],
    'router' => [
        'routes' => [
            'home' => [
                'type'    => "Literal",
                'options' => [
                    // Change this to something specific to your module
                    'route'    => '/',
                    'defaults' => [
                        'controller'    => Controller\IndexController::class,
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    // You can place additional routes that match under the
                    // route defined above here.
                ],
            ],
        ],
    ],
    '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',
            'test/index/index' => __DIR__ . '/../view/test/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ],        
        'template_path_stack' => [
            'Test' => __DIR__ . '/../view',
        ],
    ],
];

最后,我将“错误”和“布局”目录添加到我的模块"Test“中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-19 09:15:27

你必须做以下工作:

  • /config/modules.config.php中,用模块的名称替换Application。不要忘记在模块之前将Zend\Router保存在要加载的模块列表中。
  • 在您的模块中,编写类似于config/module.config.php/module/Application/config/module.config.php文件,并将application替换为模块的名称(特别是在template_map数组中)。
  • /composer.jsonautoloadautoload-dev部分中,将对"application“的引用替换为模块的名称。然后运行composer update更新composer/autoload_...文件。
  • view/error目录添加到模块的文件夹中,其中包含index.phtml404.phtml文件。
  • 在模块的文件夹中添加一个view\layout\layout.phtml文件。

小心命名空间!这应该能行。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42881408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档