Yii2: Set up Gii

Gii is very useful tool in Yii2.

Gii is provided in Yii as a module. You can enable Gii by configuring it in the modules property of the application. Depending upon how you created your application, you may find the following code is already provided in the config/web.php configuration file:

$config = [ ... ];

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',

The above configuration states that when in development environment, the application should include a module named gii, which is of class yii\gii\Module.

If you need to tell Gii about your template. The setting is made in the config file:

// config/web.php for basic app
// ...
if (YII_ENV_DEV) {    
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',      
        'allowedIPs' => ['', '::1', '192.168.0.*', ''],  
        'generators' => [ //here
            'crud' => [ // generator name
                'class' => 'yii\gii\generators\crud\Generator', // generator class
                'templates' => [ //setting for out templates
                    'myCrud' => '@app/myTemplates/crud/default', // template name => path to template

Open the CRUD generator and you will see that in the field Code Template of form appeared own template.

You can then access Gii through the following URL:


If you have enabled pretty URLs, you may use the following URL:


Note: if you are accessing gii from an IP address other than localhost, access will be denied by default. To circumvent that default, add the allowed IP addresses to the configuration:

'gii' => [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['', '::1', '192.168.0.*', ''] // adjust this to your needs

The default allowedIPs are ‘’ and ‘::1’ only, if you want any IPs will be allowed, just add ‘*’ into allowedIPs array.


'allowedIPs' => ['', '*'],

Yii Debugger can set up as same as Gii, once you set allowedIPs to ‘*’, then you will see debugger bar at bottom of page.

Screen Shot 2015-08-04 at 7.10.16 PM


About qianggan

Sr. Software Engineer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s