The UpgradeSchema will be run during module upgrade and its used to alter the table structure.
The module upgrade script will run when you run the following command line Continue reading UpgradeSchema Magento 2
The UpgradeSchema will be run during module upgrade and its used to alter the table structure.
The module upgrade script will run when you run the following command line Continue reading UpgradeSchema Magento 2
The InstallData will be run during the module install and its used to load initial data to DB table.
The module install script will run when you run the following command line
php bin/magento setup:upgrade
File : app/code/PHPCodez/First/Setup/InstallData.php
<?php namespace PHPCodez\First\Setup; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class InstallData implements InstallDataInterface { public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); $setup->getConnection()->query("INSERT INTO phpcodez_post SET name = 'Post 1'"); $setup->endSetup(); } }
The InstallSchema will be run during the module install and its used to cretae DB table structure.
The module install script will run when you run the following command line
php bin/magento setup:upgrade
File : app/code/PHPCodez/First/Setup/InstallSchema .php
<?php namespace PHPCodez\First\Setup; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\ModuleContextInterface; class InstallSchema implements InstallSchemaInterface { public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) { $installer = $setup; $installer->startSetup(); if(version_compare($context->getVersion(), '1.1.0', '<')) { if (!$installer->tableExists('phpcodez_post')) { $table = $installer->getConnection()->newTable( $installer->getTable('phpcodez_post') ) ->addColumn( 'post_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, [ 'identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true, ], 'Post ID' ) ->addColumn( 'name', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 255, ['nullable => false'], 'Post Name' ) ->addColumn( 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Created At' )->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Updated At') ->setComment('Post Table'); $installer->getConnection()->createTable($table); $installer->getConnection()->addIndex( $installer->getTable('phpcodez_post'), $setup->getIdxName( $installer->getTable('phpcodez_post'), ['name'], \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT ), ['name'], \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT ); } } $installer->endSetup(); } }
Some time its necessary to create DB tables and add data to tables. Mageto provides some classes using which you can create DB table structure or add data to tables. Following are the important classes
InstallSchema – This class can be used to setup DB structure when modules is instaled for the first time.
InstallData – This class can be used to load the initial data when modules is insttale for the first time. Continue reading SQL Setup Script Magento 2
In Magento admin grid can be created in two ways. One is using layout and another way is to use componenet.
Here I will explain grid creation using component.
Click here to read grid creation using layout.
Follow the below steps to create admin grid using component.
Continue reading Create Admin Grid Using Component Magento 2
In Magento admin grid can be created in two ways. One is using layout and another way is to use componenet.
Here I will explain grid cretaion using layout.
Click here to know grid creation using component.
Follow the below steps to create admin grid using layout
Follow the below steps to rewrite controller
Step 1 : Create di.xml file
You can rewrite controller using preference. Continue reading Magento 2 Rewrite Controller
Follow the below steps to create Admin Access Control Lists.
Step 1: Create ACL rule
Step 2: Flush Magento cache
Step 3: Check ACL rule
Step 1: Create ACL rule Continue reading Magento 2 Admin ACL
Follow the below steps to create admin manu in Magento 2.
Step 1: Create menu.xml
Step 2: Add menu item
Step 3: Flush Magento cache Continue reading Magento 2 Create Admin Menu
Follow the below steps to create View.
Step 1: Create controller
Step 2: Create layout file .xml
Step 3: Create block Continue reading Magento 2 Create View