Magento 2.0 未知模块:从命令行启用自定义模块时出错
Magento 2.0 Unknown module(s): error when enabling custom module from command line
我已经阅读了 Magento 的 DevDocs 并用 Google 搜索了这个问题,但通常缺失的 registration.php
答案不适用于此处。
我正在使用已发布的 CE 2.0.0 版本,我只是想在 magento/vendor/
中启用我的第一个最小测试模块,但是
bin/magento module:enable -c Tchsl_Test
结果:
Unknown module(s): '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__
);
我错过了什么?
我遇到了同样的问题,经过一番修改后,发现我们的模块 实际上 属于 app/code/Tchsl/Test/
。将你的模块文件移到那里,运行 shell 命令 module:status
应该会显示你禁用的模块。
您不需要将模块放在 app/code/
下。在 app/code/
中,Magento2 将搜索并找到您的模块的 registration.php
。在 Composer 的 vendor/
目录中它不会这样做,所以我们需要欺骗 Composer 加载模块的 registration.php
.
如果您在 vendor/magento/module-*
中检查任何 Magento2 模块的 composer.json
,您将看到引用 registration.php
文件的 "autoload"
部分。因此,Composer 将自动加载模块的 registration.php
,这将 "tell" Magento2 模块所在的位置。
这是 Magento Checkout 模块的 composer.json
的片段:
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\Checkout\": ""
}
}
因此,如果您将模块放在单独的存储库中并通过 composer 加载,那么这就是方法。如果您没有将它放在单独的存储库中,那么您的模块不属于 vendor/
但属于 app/code/
.
我已经阅读了 Magento 的 DevDocs 并用 Google 搜索了这个问题,但通常缺失的 registration.php
答案不适用于此处。
我正在使用已发布的 CE 2.0.0 版本,我只是想在 magento/vendor/
中启用我的第一个最小测试模块,但是
bin/magento module:enable -c Tchsl_Test
结果:
Unknown module(s): '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__
);
我错过了什么?
我遇到了同样的问题,经过一番修改后,发现我们的模块 实际上 属于 app/code/Tchsl/Test/
。将你的模块文件移到那里,运行 shell 命令 module:status
应该会显示你禁用的模块。
您不需要将模块放在 app/code/
下。在 app/code/
中,Magento2 将搜索并找到您的模块的 registration.php
。在 Composer 的 vendor/
目录中它不会这样做,所以我们需要欺骗 Composer 加载模块的 registration.php
.
如果您在 vendor/magento/module-*
中检查任何 Magento2 模块的 composer.json
,您将看到引用 registration.php
文件的 "autoload"
部分。因此,Composer 将自动加载模块的 registration.php
,这将 "tell" Magento2 模块所在的位置。
这是 Magento Checkout 模块的 composer.json
的片段:
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\Checkout\": ""
}
}
因此,如果您将模块放在单独的存储库中并通过 composer 加载,那么这就是方法。如果您没有将它放在单独的存储库中,那么您的模块不属于 vendor/
但属于 app/code/
.