Chapter 7. Creating Magento 2 Extensions – the Basics

In this chapter, we will cover the basics on how to create your own Magento 2 extensions with the following recipes:

  • Initializing extension basics
  • Working with database models
  • Creating tables using setup scripts
  • Creating a web route and controller to display data
  • Creating system configuration fields
  • Creating a backend data grid
  • Creating a backend form to add/edit data

Introduction

Now that we have installed and configured Magento 2, we will see the basics on how to create a new Magento 2 extension. If you are familiar with creating an extension for Magento 1.x, you will notice that there are some concepts that look a lot like how it is done in Magento 1. However, as the code is a completely new framework, there are also lots of changes in the module structure and necessary files.

Some of the major changes that change the way a extension is created are as follows:

  • A new module structure: The directory structure has changed, moving all parts of an extension into a single container, and files are no longer spread between different locations. This makes it easier to maintain an extension.
  • Configuration files: In Magento 2, the configuration of an extension is split into multiple smaller files that are validated by an XML Schema Definition (XSD) schema. Additionally, some configuration files can be area-specific (adminhtml, frontend, cron, and api) to overwrite the general settings.
  • Namespaces and dependency injection: In Magento 2, the code uses PHP namespaces to identify class names. Additionally, classes necessary are no longer loaded through Mage::getModel() (or similar functions), but injected into your class through a dependency injection.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.18.101