【问题标题】:Module cannot be initialized zf3 already searched internet模块无法初始化 zf3 已搜索互联网
【发布时间】:2017-04-03 14:16:37
【问题描述】:

我在 Zend Framework 3 应用程序中收到以下错误:

致命错误:未捕获 Zend\ModuleManager\Exception\RuntimeException:无法初始化模块(服务)。

我知道有一些答案,但似乎没有一个指向 zf3 并且我已经扫描了它们而没有答案。我似乎无法通过研究找到答案。

我的应用程序是否有可能没有加载模块?我只是稍微修改了应用程序配置,所以它可能只是没有加载模块本身。

我有一个文件夹结构:

- module
   -Serve
      -src
         -Module.php
         -Controller
            -IndexController.php
      -config
         -module.config.php
      -view

我已将模块添加到 /config/application.config.php 内的模块数组中。

这是我的module.config.php

namespace Serve;

return array(
        'controllers' => array(
                'invokables' => array(
                        'Serve\Controller\Index' => 'Serve\Controller\IndexController',
                ),
        ),

        // The following section is new and should be added to your file
        'router' => array(
                'routes' => array(
                        'serve' => array(
                                'type'    => 'segment',
                                'options' => array(
                                        'route'    => '/srv[/:action]',
                                        'constraints' => array(
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
                                        ),
                                        'defaults' => array(
                                                'controller' => 'Serve\Controller\Index',
                                                'action'     => 'index',
                                        ),
                                ),
                        ),
                ),
        ),

        'view_manager' => array(
                'template_path_stack' => array(
                        'album' => __DIR__ . '/../view',
                ),
                'strategies' => array(
                        'ViewJsonStrategy',
                ),
        ),
);

这是我的Serve\Module.php 文件:

<?php
namespace Serve;

class Module
{  
    public function getConfig()
    {       
        return include __DIR__ . '/../config/module.config.php';
    }
 }

我的Application\Module.php 中有一堆业务逻辑,但没有任何东西看起来会破坏加载模块。

我似乎无法通过研究找到答案。这里有什么问题?

【问题讨论】:

    标签: php zend-framework3


    【解决方案1】:

    您是否将模块添加到自动加载器? https://github.com/zendframework/ZendSkeletonApplication/blob/master/composer.json#L23

    在 ZF2 中,我们过去通过 Module 类自动加载几乎任何东西,现在我们可以在 composer 中完成,这更容易并且允许诸如 --optimize(生成类映射)和 --classmap-authoritative(执行不加载类映射之外的任何类)。

    编辑 composer.json 文件后不要忘记 composer dumpautoload :)

    【讨论】:

      猜你喜欢
      • 2013-09-03
      • 2012-11-08
      • 1970-01-01
      • 2012-08-22
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      相关资源
      最近更新 更多