我已经阅读了Magento的DevDocs并搜索了这个问题,但通常缺少的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__
);
我错过了什么?
答案 0 :(得分:1)
我遇到了同样的问题,经过一些修补,发现我们的模块实际上属于app/code/Tchsl/Test/
。将模块文件移动到那里,运行shell命令module:status
应显示已禁用的模块。
答案 1 :(得分:0)
您不需要将模块置于app/code/
之下。在app/code/
Magento2将搜索并找到您的模块registration.php
。在Composer的vendor/
目录中,它没有这样做,所以我们需要欺骗Composer加载你的模块registration.php
。
如果您要检查composer.json
中的任何Magento2模块vendor/magento/module-*
,您会看到引用"autoload"
的{{1}}部分文件。因此,Composer将自动加载您的模块registration.php
,它将&#34;告诉&#34; Magento2模块所在的位置。
这是Magento Checkout模块registration.php
中的一个片段:
composer.json
因此,如果您将模块放在单独的存储库中并通过composer加载,那么这就是要走的路。如果您没有将它放在单独的存储库中,那么您的模块不属于"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\Checkout\\": ""
}
}
,而属于vendor/
。