Skip to content
TheCoachSMB
  • Follow Us:
Email: info@gmail.com
Call: +123-456-7890
TheCoachSMB

We Make It Happen

  • Blog
    • Magento2
    • HTML5
    • PHP Tutorial
  • Our Courses
  • Services
    • Magento 2 Installation Service
    • Magento Development Services
    • Support & Maintenance Services
    • Migration Services
    • Magento 2 Upgrade Service
    • Magento Security Patches
    • Magento Site Audit
    • Magento Speed & Performance
    • Magento Extension Development
    • Magento Consulting Services
    • SEO Services
    • Designing Services
  • Book A Call
  • Profile
  • About Us

    Lorem Ipsum is simply dummy text of the printing and typesetting industry.

    Contact Us
    Contact Info

    684 West College St. Sun City, United States America, 064781.

    (+55) 654 - 545 - 1235

    info@gmail.com

  • Get In Touch
  • Follow Us:
Email: info@gmail.com
Call: +123-456-7890
TheCoachSMB

We Make It Happen

  • Get In Touch
  • Blog
    • Magento2
    • HTML5
    • PHP Tutorial
  • Our Courses
  • Services
    • Magento 2 Installation Service
    • Magento Development Services
    • Support & Maintenance Services
    • Migration Services
    • Magento 2 Upgrade Service
    • Magento Security Patches
    • Magento Site Audit
    • Magento Speed & Performance
    • Magento Extension Development
    • Magento Consulting Services
    • SEO Services
    • Designing Services
  • Book A Call
  • Profile

Magento 2 – How to Build a Complete Module

  • Home
  • Magento 2 – How to Build a Complete Module
  • Sonal Motghare-Balpande Sonal Motghare-Balpande
  • Apr, Sat, 2018
  • Magento 2
Magento 2 – How to Build a Complete Module

Table of Contents

  • Introduction
  • Step 1: Create Magento 2 Module Structure
  • Step 2: Declaration of Module
  • Step 3: Registration of Module
  • Step 4: Activate the Module
  • Step 5: Add functionality – Display module link in the footer
  • Step 6: Enable/Disable Module depending on the admin setting
  • Conclusion

Introduction

Modules together form the Magento2 platform. The whole Magento 2 system is built with different unique Magento system core modules and that’s the reason it is called as modular system.

This means all functionalities or business logic is designed and developed as modules. Every module can work pretty much as a standalone unit or with minimum dependencies with other modules.

Apart from default functionalities provided by the Magento 2, magento site owners and users require some of the custom functionalities to meet their business needs. Or sometimes it needs to override the default Magento functions as per the business requirements.

So in these cases, Magento developer needs to build up the module (called as custom module) and implement the logic based on the business/online store’s requirement.

Since Magento is an open source ecommerce platform, we can add/install our developed custom module on it.

Now, in order to create a Magento 2 Module, you need to first install Magento 2 either locally or on a development server, that you can add new files to. The version of Magento that you use doesn’t really matter, because we will be covering fundamental aspects that exist across all versions and editions: Community, Professional and Enterprise.

Here’s an easy-to-follow tutorial on How to Install Magento 2 on Windows  or Install Magento2 on Linux/Ubuntu in case if you’ve not yet installed Magento 2.

The building of complete module is divided into 4 parts:

    • PART 1 – This is the first part of the article
    • PART 2 – Create Custom Module URL and Display Content in Magento2
    • PART 3 – How to Create and Insert Data in Custom Database Table in Magento 2?
    • PART 4 – Display Data From Database On Frontend in Magento2

Let’s discuss the first part here…

So are you ready to create our first Magento2 module !!!!

We are going to implement this in following steps:

  • Step 1: Create Magento 2 Module Structure
  • Step 2: Declaration of Module
  • Step 3: Registration of Module
  • Step 4: Activate the Module
  • Step 5: Add functionality – Display module link in the footer
  • Step 6: Enable/Disable Module depending on the admin setting`

Let’s start creating module by following below steps:-

Step 1: Create Magento 2 Module Structure

There are two locations where a module can be located in a Magento 2 application.

The first location is an app/code directory. This directory is used to add all custom and 3rd-party Magento 2 modules. This location is usually used by development agencies, internal or in-house developers in order to simplify a development process.

The second location is a vendor directory. All the Magento 2 core modules are located under vendor/magento. Example –

The above is a standard module folder structure. This is the folder structure of the Magento catalog module.

1. Create the following folders in the magento project root directory (ex. – C:\xampp\htdocs\magento2):

  • app/code/Thecoachsmb
  • app/code/Thecoachsmb/Mymodule

The Thecoachsmb folder is the module’s VendorName, and Mymodule is the ModuleName.

Note: If you don’t have the code folder in your app directory, create it manually.

Now, create app/code/Thecoachsmb/Mymodule/composer.json:

Contents would be:

{}

This file will be loaded by Composer every-time you run it even though we are not actually using Composer with our module.

Step 2: Declaration of Module

It is necessary to create etc folder and add the module.xml file in it

  app/code/Thecoachsmb/Mymodule/etc/module.xml

Contents would be:

<?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="Thecoachsmb_Mymodule" > 
     <sequence> 
         <module name="Magento_Directory"/> 
         <module name="Magento_Config"/> 
     </sequence>
 </module> 
</config>

Step 3: Registration of Module

To register the module, create a registration.php file in the app/code/Thecoachsmb/Mymodule/registration.php

Contents would be:

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

Step 4: Activate the Module

Now its time to enable our moule. Lets check the status of our module by typing below command in the magento project root directory (ex. – C:\xampp\htdocs\magento2) as:

php bin/magento module:status

You should see the module is disabled now:

List of disabled modules: Thecoachsmb_Mymodule

If you get the error “No connection could be made because the target machine actively refused it.” then follow this link.

So lets run the command to enable our module:

php bin/magento module:enable Thecoachsmb_Mymodule

Now that you have enabled the module first time, so you have to upgrade the database of the module by using this command line:

php bin/magento setup:upgrade && php bin/magento se:s:d -f

After successfully enabling the module, recheck the status of modules with the command line that was mentioned before.

Step 5: Add functionality – Display module link in the footer

Now we will display our module link MyModule in the footer area.

For this, create default.xml file in path app\code\Thecoachsmb\Mymodule\view\frontend\layout\default.xml

and add below code  in it:-

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
       <referenceBlock name="footer_links">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="mymodule-link">
            <arguments>
                 <argument name="label" xsi:type="string" translate="true">My Module</argument>
                 <argument name="path" xsi:type="string">mymodule</argument>
            </arguments>
        </block>
      </referenceBlock>
    </body>
</page>

and save the file. and check in the site, it will show our module link in the footer.

Step 6: Enable/Disable Module depending on the admin setting

Its time to add functionality of enabling and disabling our custom module from admin so that anyone who has admin access can do it. To do so, create system.xmlfile in app/code/Thecoachsmb/Mymodule/etc/adminhtml  path

Content would be:-


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
     <system>
        <tab id="thecoachsmb" translate="label" sortOrder="200">
           <label>Thecoachsmb</label>
        </tab>
        <section id="thecoachsmb" translate="label" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
           <class>separator-top</class>
           <label>Mymodule</label>
           <tab>thecoachsmb</tab>
           <resource>Thecoachsmb_Mymodule::configuration</resource>
           <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>General Configuration</label>
                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                     <label>Enable Module</label>
                     <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
          </group>
       </section>
     </system>
</config>

After adding this code, Flush the Cache. Then Go to admin panel->Stores->Configuration and check our module configuration.

 

Solved – Admin links not working in Magento2

Lets update “ifconfig=”section_id/group_id/field_id“” line in the block of the reference “footer_links” in file app\code\Thecoachsmb\Mymodule\view\frontend\layout\default.xmllike this

<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="thecoachsmb/general/enable" name="mymodule-link"> 

What if we want to automatically enable this module when we will install this module, to do so create config.xml file in path app\code\Thecoachsmb\Mymodule\etc.

And content would be :-

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
     <default>
        <thecoachsmb>
           <general>
                <enable>1</enable>
           </general>
         </thecoachsmb>
     </default>
</config>

Now, clear cache-

php bin/magento c:f

You can put the path to the field in the <default> element to set value default for it.

The belowis the format of config.xml file:

<default>
    <section_id>
        <group_id>
            <field_id>{value}</field_id>
        </group_id>
    </section_id>
</default>

Thats All.

Watch this video by clicking on below link.

Conclusion

In this way, we created the first module giving link in the footer and added functionality in the admin panel for enabling and disabling this.

Now its time to create Create Custom Module URL and Display Content in Magento2.

Hope you liked this article, Also please comment below giving your feedback. Your feedback is very important to us.

Related Posts:

  • Events and Observers in Magento2
  • How To Create A New Admin Menu and Sub-Menu In Magento 2
  • Magento 2 Create Shipping Method
  • How to add modal popup in Magento 2
  • How to Add Order Attribute in Magento2?
  • How to set custom Price for Products in Cart in Magento 2
add custom footer linksmagento 2 complete module complete module in magento2 custom module development in magento2 enable and disable functionality in magento2 admin enable module in Magento2 how to add header link in magento 2 magento 2 add custom link to top links magento 2 header links phtml registration of the module in magento2
Comments (10)
Sonal Motghare-Balpande

Hello Readers, My passion is to guide people by sharing the knowledge I have. If I can contribute even little to the people life, its very big achievement for me. Thank You, Sonal

One thought on “Magento 2 – How to Build a Complete Module”

  1. kushwah anuj says:
    December 2, 2022 at 11:02 AM

    I want to disable two column from sales order

    Reply
    1. Sonal Motghare-Balpande says:
      December 3, 2022 at 3:12 PM

      In the layout file, change the layout=”” to something you want like, 1column, 2columns-left or 2columns-right, or 3columns

      Reply
  2. kresosusec.suec1 says:
    July 6, 2022 at 5:32 AM

    When i add system.xml into Magento 2 and then press configuration in backend, i receive error message. I have magento2 2.4.4, i have follow your instructions with no mistake. Please help, so i can finish your tutorial for custom modules. This don’t help
    1.”Open up app/etc/di.xml in the editor
    2..Find the path “Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink”
    3.and replace to “Magento\Framework\App\View\Asset\MaterializationStrategy\Copy”
    Clear Cache”.

    Reply
    1. Sonal Motghare-Balpande says:
      July 27, 2022 at 8:33 PM

      I crossed checked the code. It is working. Can you please check the proper
      – file name and
      – file location
      – file content

      Thanks,

      Reply
  3. Santhosh says:
    November 23, 2021 at 10:57 AM

    Thank you so much. This is really easy

    Reply
  4. Biplab Mukherjee says:
    September 9, 2021 at 3:53 PM

    Hi Maam you video is very easy to learn, it would be good if you do a video for custom theme development for a html to magento2 theme creation

    Reply
  5. Thilip says:
    August 28, 2021 at 2:22 PM

    adminhtml/Magento/backend/en_US/requirejs/require.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff) —–> Becaus of this error Magento frontend & backend UI are not loading properly. Could you please help me to fix this mam… Thanks in advance.

    Reply
    1. Sonal Motghare-Balpande says:
      August 28, 2021 at 2:45 PM

      You can solve it by the following ways

      – Remove all files from var/ folder by using this command sudo rm -rf var/* (For Ubuntu)
      – Check for .htaccess in pub/static. If not exists, take a file from a fresh setup.
      – Run the following commands
      1. php bin/magento setup:static-content:deploy -f
      2. php bin/magento indexer:reindex
      3. php bin/magento cache:clean
      – Now, please refresh your browser for frontend and backend pages.

      Please feel free to comment if you need more details.

      Thank you !!

      Reply
  6. Hemalata says:
    July 2, 2021 at 7:50 AM

    Thank you so much
    Your blogs are very helpful to us..!!!

    Reply
    1. Sonal Motghare-Balpande says:
      July 2, 2021 at 10:42 AM

      Thank you Hemalata !!

      Reply

Leave a Reply to Santhosh Cancel reply

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

Search
Recent Posts

  • Install/debug Magento2 delivery date extensionNovember 18, 2024
  • Install Magento 2.4.6 on Ubuntu 22.04 [Complete Guide]October 16, 2024
  • Install Magento 2.4.7 on Ubuntu 22.04 [Complete Guide]October 16, 2024
Categories

  • Accounting
  • Agency
  • Business
  • Consultant
  • Finance
  • Investment
  • Magento 2
  • Masonry
Calendar
May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Nov    
Tags

6 Steps to Install Magento 2 on XAMPP Windows Using Composer Agency Business composer install magento 2 download xampp for windows Graphics how to install magento how to install magento2 in localhost how to install magento2 in localhost ubuntu how to install magento2 in localhost wamp how to install magento 2 in windows 10 How To Install Magento2 in Windows on localhost using Xampp how to install magento 2 on xampp How to install Magento 2 using Composer in windows How to install Magento 2.4 in localhost XAMPP how to install magento 2.4 on xampp install magento 2 in windows10 install magento 2 using composer install magento 2 using composer windows install magento 2 windows xampp install Magento 2 with Sample Data install magento2.4 Install Magento 2.4 xampp windows 10 install magento 2.4.3 install magento2.4.3 install xampp on windows 10 Latest magento2 magento 2 composer install magento 2 install magento2 install magento 2 installation magento 2 installation steps magento 2 installation using composer magento 2 system requirement magento2.4 magento2.4.3 magento download magento for windows magento installation on xampp Magento with windows magneto2 Multisite thecoachsmb xampp download

LATEST BUSINESS IDEAS

Subscribe to Our Newsletter
& Stay Update

Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.

Thank you to visit our site and doing business with us.

We give our 100% to help you and to grow together.

About Us

Ready To Start Work With Us?

Felis consequat magnis est fames sagittis ultrices placerat sodales porttitor quisque.

Get a Quote
Contact Us
  • Courses
  • Blog
  • Magento2 Tutorial
  • Shop
Quick Links
  • Appointment
  • Price Plans
  • Investment Strategy
  • Financial Advices
  • Strategy Growth
  • Services
  • Business Planning
Links
  • Privacy Policy
  • Terms and Conditions
  • My Account
  • Contact Us
  • About Us
Latest Posts
  • Install/debug Magento2 delivery date extensionNovember 18, 2024
  • Install Magento 2.4.6 on Ubuntu 22.04 [Complete Guide]October 16, 2024
  • Install Magento 2.4.7 on Ubuntu 22.04 [Complete Guide]October 16, 2024
Open Hours

Our support available to help you.

  • Monday-Friday: 10am to 10pm
  • Email: support@thecoachsmb.com
  • Call: +91 7020500374
Opening Hours
Week Days 10:00 - 17:00
Saturday 10:00 - 15:00
Sunday Day Off
Contact us
Copyright © 2025 TheCoachSMB
🚀 Let’s Connect on LinkedIn! 🚀

Want to level up your skills and knowledge? 🚀
Follow us on LinkedIn to get:
✅ Expert insights on business growth
✅ Daily tips to sharpen your skills
✅ Exclusive updates from The Coach SMB

Let's grow together!

Follow me on LinkedIn

No thanks, I’m not interested!

WhatsApp

WhatsApp

Skype

Skype

Hide