Using Gii to create room, customer, and reservation models in yii

Using Gii to create room, customer, and reservation models in yii

Try out part 1 of this series ! before exploring this tutorial ..

Yii2 provides a powerful tool to generate models, controllers, and CRUD (create, read, update, and delete) actions, forms, modules, and extensions: Gii.

At the bottom of the basic/config/web.php file, placed in the basic standard configuration, there is a block of code that enables Gii:

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yiidebugModule';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yiigiiModule';
}

Verify that these lines are present, otherwise append them at the bottom of the web.php file before the return $config statement. The last check is in basic/web/index.php. Verify that YII_ENV is dev, with this line:

defined('YII_ENV') or define('YII_ENV', 'dev');

Now, we can point our browser to http://hostname/basic/web/gii, and we should see this error page:

Using Gii to create room, customer, and reservation models
Recommended :  Introduction to symfony

Forbidden access to Gii

This page will be displayed since access to Gii is locked by a password.

We need to add extra configuration to the gii module, passing other allowed IPs. Gii’s configuration has an attribute named allowedIPs, which consents to specify which IP addresses can access the Gii page:

 'allowedIPs' => ['127.0.0.1', '::1', '192.168.178.20']

In this extract, Gii will accept access from a localhost (in the IPv4 form with 127.0.0.1 and IPv6 form with ::1) and from 192.168.178.20, which should be our IP address in private network.

If the Yii2 application is running on an external hosting, we will set our IP public address in this list of allowed IPs. For example, if our IP is 66.249.64.76, this entry will be appended to existent (if we want maintain other permitted access points):

 'allowedIPs' => ['127.0.0.1', '::1', '192.168.178.20', '66.249.64.76']

To allow access from everywhere (useful in the development stage), we can add * in this list, which means that the Gii page can be accessed from every IP address:

'allowedIPs' => ['127.0.0.1', '::1', '192.168.178.20', '*']

Consequently, the content of gii]['gii'] = 'yiigiiModule' is:

    $config['modules']['gii'] = [
        'class' => 'yiigiiModule',
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.178.20', '*'] ]; configuration in basic/config/web.php will be:
if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yiidebugModule';

    $config['bootstrap'][] = 'gii';
    //$config['modules'
}

 

Recommended :  How to Minimize the assets in yii 2 framework

 

About the author

Deven Rathore

I'm Deven Rathore, a multidisciplinary & self-taught designer with 3 years of experience. I'm passionate about technology, music, coffee, traveling and everything visually stimulating. Constantly learning and experiencing new things.

Pin It on Pinterest

Shares