Reading list Switch to dark mode

    Magento 2 Development 01: Module Registration

    In this blog we will create our first module with name “BlogManager”.

    Before diving into developing, let’s set the mode to Developer so that we can see errors if occur, on the browser itself. To set the mode we have to run the command php bin/magento deploy:mode:set developer from the magento root directory (the directory where magento is installed). There are three modes in Magento 2, (i) Developer, (ii) Default and (iii) Production.

    To create module the module we have to create vendor folder with vendor name (which is Webkul in our case) under app/code folder (if code folder is not available then please create it). Then we have to create the module folder “BlogManager” (the module name).

    First we have to register our module with registration.php so that magento can recognise it as a module. The registration.php will be under module folder and the content will be

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

    Types of components are,
    i) Module
    ii) Theme
    iii) Language
    iv) Library

    Searching for an experienced
    Magento 2 Company ?
    Read More

    Now we need to create etc folder under the module directory and in the etc folder we need to create module.xml file with following content

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Webkul_BlogManager">
        </module>
    </config>

    Earlier (before Magento 2.4) we use to write module version in module tag like <module name="Webkul_BlogManager" setup_version="2.0.0">

    After creating these two files we need to run the setup upgrade command like below. It will activate the module.

    php bin/magento setup:upgrade

    Folder structure should look like,

    2021-01-27_19-32
    2021-02-06_11-11

    Note that we have to run all the magento commands from magento root directory as shown below,

    command

    P.S. To view all the errors we have to uncomment a line in app/bootstrap.php file,

    view errors

    Make sure the module is enabled as well

    php bin/magento module:enable Webkul_BlogManager

    Next blog -> Magento 2 Development 02: Route Management and Controllers

    . . .
    Add a comment

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top
    We endeavoured to re-platform our existing site and Webkul has been playing an integral part as far as transforming our basic Magneto instance into an online marketplace.
    Alex Maranduik
    Director, Marketing
    www.labx.com
    Talk to Sales

    Global

    Live Chat

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home