Create a Yii 2 Module

In this tutorial, you will learn how to generate and configure a Yii 2 module.

So letes get started!

First make sure you have installed Yii framework template,either basic or advanced template will do.

We will use Yii 2’s Gii tool to help you generate templates for the module.

To can access Yii 2 Gii tool navigate to yourdomain/index.php?r=gii .

                                                                                            Yii 2 Gii tool interface

Step 1: Select the Module Generator option

Step 2: Enter your module ID and Class

In this case my module ID is post and the Module class is backend\modules\post\PostModule.



Step 3: Click Preview button to preview then Generate button to generate the files shown in the preview.

Step 4: Add the Post module to your application configuration:

Add the Module class to your modules  configuration

'post' => [
            'class' => 'backend\modules\post\PostModule',

Add Module alias to to alias array

'aliases' => 
       'post' => '@backend/modules/post',
Module file structure

You now have your module! access it in the backend  by navigating to yourdomain/backend/post/default/index

Thanks for reading this far, if helpful let alot of folks know it.:)

Leave a Reply

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