01.08.2016

Magento 2. Magento Backend. Part IV.

Creating a grid of a database table

(We need the module that we created in the previous recipes)
 

STEP I – Adding the ACL for grid page:

Change the file:

app/code/Magedd/Education/etc/acl.xml
Add the following line of code as a child of the <resource id=”Magento_Backend::admin”>:

STEP II – Creating a menu item for the page:

Change the file:

app/code/Magedd/Education/etc/adminhtml/menu.xml
Add the following code as a child of the <menu> tag:

STEP III – Creating the controller action:

Create the file:

app/code/Magedd/Education/Controller/Adminhtml/Subscription/Index.php

STEP IV – Creating the grid container block:

Create the file:

app/code/Magedd/Education/Block/Adminhtml/Subscription.php

STEP V – Adding the grid block:

Create the file:

app/code/Magedd/Education/Block/Adminhtml/Subscription/Grid.php

STEP VI – Adding layout update:

Create the file:

app/code/Magedd/Education/view/adminhtml/layout/education_subscription_index.xml

STEP VII – Clean cache by CLI:

 
/var/www/local/{your-project-name.dev} >  php bin/magento cache:clean
 
Reload the page /admin/education/subscription/ . You will see the empty grid:
 
magento2-grid
 
You can insert new values from phpmyadmin or wait for next articles.