为什么在Magento-2.0.0-RC中添加了注册.PHP?
-
13-12-2019 - |
题
最近的magento-2.0.0-RC
启动,它们在每个模块根文件夹中添加了生成的registration.php
?所以我只是想知道有没有理由?
有人可以把光线放在这个吗?
解决方案
registration.php
是模块的入口点的类型。它是来自Magento 1的相当于app/etc/modules/[Namespace]_[Module].xml
但现在,是模块本身的一部分。
它允许您在app/code
文件夹中和vendor
文件夹中创建模块。
无论您在哪里添加它,此文件将由Magento拾取,您的模块将被考虑。
其他提示
我注意到两件事是从magento ver改变的。1.0.0-beta(OCT)到Magento ver。2.0.0-RC2
1.在名为Registration.php的模块的根文件夹中添加了新文件
ex:-app \ code \ sugarcode \ test \ staring.php
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Sugarcode_Test',
__DIR__
);
.
2。event.xml已更改 以前我们在Event.xml中提到了在Observer标记中的方法名称现在删除了方法,所以只需要提到
的实例<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="sales_order_grid_collection_load_before">
<observer name="sales_order_grid_test" instance="Sugarcode\Test\Observer\Addtest" />
</event>
</config>
.
和在/ moduleename / Observer文件夹中,您需要创建一个功能
的文件public function execute()
.
是
<?php
namespace Sugarcode\Test\Observer;
class Addtest
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$obj=$observer->getEvent()->getOrderGridCollection();
$obj->getSelect()->joinLeft(
['testt' => 'testtable'],
"(main_table.entity_id = testt.id)",
[
'testt.title as title'
]
);
//$this->printlogquery(true);
//return $obj;
}
}
.