我已经安装了ZF3,默认情况下模块是“应用程序”。我想改变这个模块在默认情况下由其他。我怎么能这么做?
编辑I:我做了一些更改,但它不起作用:
/config/modules.config.php
return [
'Zend\Router',
'Zend\Validator',
'Test',
];/module/Test/config/module.config.php
<?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
return [
'Zend\Router',
'Zend\Validator',
'Test',
];/module/Test/config/module.config.php
<?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“中。

发布于 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.json的autoload和autoload-dev部分中,将对"application“的引用替换为模块的名称。然后运行composer update更新composer/autoload_...文件。view/error目录添加到模块的文件夹中,其中包含index.phtml和404.phtml文件。view\layout\layout.phtml文件。小心命名空间!这应该能行。
https://stackoverflow.com/questions/42881408
复制相似问题