15

Recently magento-2.0.0-RC was launched and they added registration.php in every module root folder? So I just want to know is there any reason for that?

Can someone put light on this?

12

registration.php is kind of the entry point of your module. It's the equivalent of app/etc/modules/[Namespace]_[Module].xml from Magento 1.
But now, is part of the module itself.
it allows you to create modules in the app/code folder and in the vendor folder as well.
No matter where you add it, this file will be picked up by Magento and your module will be taken into consideration.

  • Where you add it means I can place this file anywhere like block,model or controller directory or any other directory ? @Marius – Keyur Shah Nov 10 '15 at 9:16
  • And is there any reason for that because config.php is already there @Marius – Keyur Shah Nov 10 '15 at 9:22
  • 2
    in config.php only the module names appear and their status (enabled/disabled). There is no path to the module. Like I said in the answer, registration.php allows you to have modules outside app/code – Marius Nov 10 '15 at 9:24
  • 3
    See this for more details: maxyek.wordpress.com/2015/03/27/… – Marius Nov 10 '15 at 9:25
  • @Marius : So the module should not work without registration.php right? – Sukeshini Jul 13 '16 at 7:16
1

i noticed two thing was changed from Magento ver. 1.0.0-beta (Oct) to Magento ver. 2.0.0-rc2
1. added new file in root folder of module called registration.php ex:-app\code\Sugarcode\Test\registration.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 was changed previous we are mention method name in observer tag in event.xml now method was removed juts you need to mention only instance that is

<?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>

and in /ModuleName/Observer folder you need to create a file with function

public function execute()

that is

<?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;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.