【问题标题】:Magento 2.0 Unknown module(s): error when enabling custom module from command lineMagento 2.0 未知模块:从命令行启用自定义模块时出错
【发布时间】:2016-03-16 04:10:52
【问题描述】:

我已阅读 Magento 的 DevDocs 并在 Google 上搜索过这个问题,但通常缺少的 registration.php 答案不适用于此处。
我在发布的 CE 2.0.0 版本上,我只是想在magento/vendor/ 中启用我的第一个最小测试模块,但是

bin/magento module:enable -c Tchsl_Test

结果:

未知模块:“Tchsl_Test”

我基于vendor/magento/中模块的命名约定和文件位置

vendor/tchsl/module-test/etc/module.xml我有

<config xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Tchsl_Test" />
</config>

vendor/tchsl/module-test/registration.php我有

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Tchsl_Test',
    __DIR__
);

我错过了什么?

【问题讨论】:

    标签: magento-2.0


    【解决方案1】:

    我遇到了同样的问题,经过一番修改后,发现我们的模块实际上属于app/code/Tchsl/Test/。将你的模块文件移到那里,运行 shell 命令module:status 应该会显示你禁用的模块。

    【讨论】:

      【解决方案2】:

      您不需要将您的模块放在app/code/ 下。在app/code/ Magento2 将搜索并找到您模块的registration.php。在 Composer 的 vendor/ 目录中它不会这样做,因此我们需要欺骗 Composer 加载您模块的 registration.php

      如果您在vendor/magento/module-* 中检查任何Magento2 模块的composer.json,您将看到引用registration.php 文件的"autoload" 部分。因此 Composer 将自动加载您模块的 registration.php,这将 “告诉” Magento2 您的模块所在的位置。

      这是来自Magento Checkout 模块的composer.json 的片段:

      "autoload": {
          "files": [
              "registration.php"
          ],
          "psr-4": {
              "Magento\\Checkout\\": ""
          }
      }
      

      因此,如果您将模块放在单独的存储库中并通过 composer 加载,那么这就是要走的路。如果您没有将它放在单独的存储库中,那么您的模块不属于vendor/,而是属于app/code/


      另见this Magento Stack Exchange post

      【讨论】:

        猜你喜欢
        • 2011-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-22
        • 2016-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多