【问题标题】:Cannot install ZfcUser / ZfcBase in ZF2 Skeleton Application无法在 ZF2 Skeleton Application 中安装 ZfcUser / ZfcBase
【发布时间】:2013-04-01 06:45:25
【问题描述】:

我无法将 ZfcUser / ZfcBase 模块安装到 ZF2 骨架应用程序中。 (Ubuntu 12.10 服务器、Apache、PHP5.4.6)

1) 下载并解压 ZF2 骨架应用程序

2) 下载 ZF2 库并解压到 /vendor/ZF2

此时,骨架应用程序工作正常。

3) 下载 ZfcBase 和 ZfcUser 并将其解压缩到 /vendor/ 中(例如,我有 /vendor/ZfcXxxx/Module.php)

4) 编辑 config/application.config.php 以包含两个新模块

<?php
return array(
    // This should be an array of module namespaces used in the application.
    'modules' => array(
        'Application',
        'ZfcBase',
        'ZfcUser',
    ),

我现在明白了

Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZfcBase) could not be initialized.' in /home/ubuntu/zf2-skel/vendor/ZF2/library/Zend/ModuleManager/ModuleManager.php:144
Stack trace:
#0 /home/ubuntu/zf2-skel/vendor/ZF2/library/Zend/ModuleManager/ModuleManager.php(85): Zend\ModuleManager\ModuleManager->loadModule('ZfcBase')
#1 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#2 /home/ubuntu/zf2-skel/vendor/ZF2/library/Zend/EventManager/EventManager.php(464): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#3 /home/ubuntu/zf2-skel/vendor/ZF2/library/Zend/EventManager/EventManager.php(208): Zend\EventManager\EventManager->triggerListeners('loadModules', Object(Zend\ModuleManager\ModuleEvent), NULL)
#4 /home/ubuntu/zf2-skel/vendor/ZF2/library/Zend/ModuleManager/ModuleManager.php(104): Zend\EventManager\EventManager->trigger('loadModules', Object(Zend\ModuleManager\ModuleManager), Object(Zend\ModuleMan in /home/ubuntu/zf2-skel/vendor/ZF2/library/Zend/ModuleManager/ModuleManager.php on line 144

大概我缺少一些自动加载配置...

【问题讨论】:

    标签: zend-framework2 zfcuser


    【解决方案1】:

    使用 composer.phar 非常有用。

    php composer.phar self-update
    php composer.phar install
    

    无论如何检查您的“autoload_classmap.php”并验证 ZfcBase 的添加。

    【讨论】:

      【解决方案2】:

      我没有使用作曲家(出于各种原因)。这个缺少的配置告诉应用程序加载模块的 autoload_classmap.php 文件就是这样。

      Zend\Loader\AutoloaderFactory::factory([
          'Zend\Loader\StandardAutoloader' => [
              'autoregister_zf' => true
          ],
          'Zend\Loader\ClassMapAutoloader' => [
              __DIR__ . '/../vendor/ZfcBase/autoload_classmap.php',
              __DIR__ . '/../vendor/ZfcUser/autoload_classmap.php',
          ],
      ]);
      

      【讨论】:

      • Composer 创建了它自己的autoload_classmap,因此绝对不需要使用模块提供的那些。 Composer 为您通过 composer 管理的所有模块创建一个 Classmap。
      • 除了@Sam 所说的之外,请考虑您不应该永远考虑模块的内部结构。相反,调整config/application.config.php 中的module_paths 选项,因为模块应该提供自己的自动加载
      • @Sam/Ocramius。我没有使用作曲家。你是说如果我想使用第三方模块,那么我必须使用composer?没有它就没有(可接受的)使用/配置第三方模块的方法吗?
      • 当然你可以在没有 composer 的情况下使用这些模块。我们只建议使用它,因为 composer 就像是当前了解的工具。 Ocramius 指出了您一直在寻找的答案 - 最可能的情况是您的 module_paths 配置中缺少 /vendor 路径
      猜你喜欢
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 2013-03-30
      相关资源
      最近更新 更多