我已经安装了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时获得的结果是:
致命错误:未捕获Zend \ View \ Exception \ RuntimeException: Zend \ View \ Renderer \ PhpRenderer :: render:无法呈现模板 &#34;错误&#34 ;;解析器无法解析为文件 C:\ Apache24 \ htdocs中\店\厂商\ zendframework \ Zend的视图\ SRC \渲染\ PhpRenderer.php:494 堆栈跟踪:#0 C:\ Apache24 \ htdocs中\店\厂商\ zendframework \ Zend的视图\ SRC \ View.php(207): Zend \ View \ Renderer \ PhpRenderer-&gt; render()#1 C:\ Apache24 \ htdocs中\店\厂商\ zendframework \ Zend的视图\ SRC \ View.php(236): Zend \ View \ View-&gt; render(Object(Zend \ View \ Model \ ViewModel))#2 C:\ Apache24 \ htdocs中\店\厂商\ zendframework \ Zend的视图\ SRC \ View.php(200): Zend \ View \ View-&gt; renderChildren(Object(Zend \ View \ Model \ ViewModel))#3 C:\ Apache24 \ htdocs中\店\厂商\ zendframework \ Zend的-MVC \ SRC \视图\ HTTP \ DefaultRenderingStrategy.php(105): Zend \ View \ View-&gt; render(Object(Zend \ View \ Model \ ViewModel))#4 C:\ Apache24 \ htdocs中\店\厂商\ zendframework \ Zend的-eventmanager进行\ SRC \ EventManager.php(322): 的Zend \的mvc \视图\ HTTP \ DefaultRenderingStrategy-&GT;呈现(对象(的Zend \的mvc \ MvcEvent)) 5 C:\ Apache24 \ htdocs \ shop \ ve在C:\ Apache24 \ htdocs \ shop \ vendor \ zendframework \ zend-view \ src \ Renderer \ PhpRenderer.php 在第494行
编辑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',
],
],
];
最后,我添加了#34;错误&#34;和&#34;布局&#34;目录到我的模块&#34;测试&#34;。
答案 0 :(得分:2)
您必须执行以下操作:
/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
文件。小心命名空间! 这应该有用。