Enable Gii Module In Yii2

 ·  · 

Tutorial about how to enable Gii module of Yii2.

 

1 Install Gii

Edit composer.json file of your project, and add following dependency:

"require-dev": {
    "yiisoft/yii2-gii": "*"
},

Then update your Composer dependencies.

$ composer update

Alternatively, you can let Composer do these automatically.

$ composer require --dev "yiisoft/yii2-gii:*"

 

2 Configuration

2.1 Basic Template

For Yii2 basic project template, the configuration is in config/web.php file of your project.

if (YII_ENV_DEV) {
    // ...

    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['*'],

        // or allow localhost only
        // 'allowedIPs' => ['127.0.0.1', '::1'],
    ]

    // ..
}

2.2 Advanced Template

For example, to enable Gii in backend of your advanced project template, you should edit backend/config/main-local.php:

if (!YII_ENV_TEST) {
    // ...

    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['*'],

        // or allow localhost only
        // 'allowedIPs' => ['127.0.0.1', '::1'],
    ]

    // ..
}

3 Access

After enabling Gii module you can access it by URL: http://your_app_path/index.php?r=gii.