How to register module and form database in Magento 2

In this tutorial, we will discuss how to register module and form database in Magento 2, the following steps are:

Step 1: Classify some basic information about the component

Step 2: In our module all source code will located at: app/code/Webnexs/Company.

Step 3: Now we start by creating two file in app/code/Webnexs/Company folder

Step 4: Form routes.xml in app/code/Webnexs/etc/adminhtml

Step 5: Form installScheme.php in app/code/Webnexs/Setup folder

Step 6: Update project by command-line

How to register module and form database in Magento 2

  • In this series, I will show you to create a complete admin module for basic function Magento 2: list, edit, add new, filter, export, delete.
  • UI component: We will use the new type UI which produces Magento 2.
  • The business environment of these volumes is this: I’m going to write a volume to manage my corporate staff. So in this tutorial, you can guide, create, edit, delete, and create a section of the list.

Classify some basic information about the component

Vendor name: Webnexs.

Module name: Company

Database table : company_staffs.

Staff_id: number

Staff_name: text (255)

Staff_email: text (255)

Staff_status: boolean (true/false)
  • In Magento 2, we set all of our module code in to app/code/your_company_name/your_module_name
  • But if you install a module with composer, all code will be found at: app/vendor/your_company_name/your_module_name

In our module all source code will located at: app/code/Webnexs/Company

App/code/Webnexs/company
Block

    Adminhtml

Controller

    Adminhtml

Model

Setup

etc

    Adminhtml

View

Now we start by creating two file in app/code/Webnexs/Company folder

  • Composer.json
{

  "name": "Webnexs/module-company",

  "description": "N/A",

  "require": {

    "php": "~5.5.0|~5.6.0|~7.0.0"

  },

  "type": "magento2-module",

  "license": [

    "OSL-3.0",

    "AFL-3.0"

  ],

  "authors": [

    {

      "name": "Steve Ngo",

      "email": "[email protected]",

      "homepage": "https://www.Webnexs.com/",

      "role": "Developer"

    }

  ],

  "autoload": {

    "files": [

      "registration.php"

    ],

    "psr-4": {

      "Webnexs\\Company\\": ""

    }

  }

}
  • Registered.php
<!--?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Webnexs_Company', __DIR__ ); &lt;/code&gt; &lt;/pre&gt; &lt;p&gt;&lt;b&gt;Step 4: create module.xml file in app/code/Webnexs/etc&lt;/b&gt;&lt;/p&gt; &lt;p&gt;app/code/Webnexs/etc/module.xml&lt;/p&gt; &lt;pre&gt; &lt;code&gt; &lt;?xml version="1.0" encoding="UTF-8"?-->

Form routes.xml in app/code/Webnexs/etc/adminhtml

app/code/Webnexs/etc/Adminhtml/routes.xml
<!--?xml version="1.0" encoding="UTF-8"?-->

Form installScheme.php in app/code/Webnexs/Setup folder

app/code/Webnexs/Setup/InstallSchema.php

Update project by command-line

  • Open terminal and run the command line to upgrade the mission
php -f bin/magento setup:upgrade
  • At this point, you have a module created for Magento and registration information.


Posted

in

by

Tags:

Comments

Leave a Reply

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