Gii Problems On Creating Simple Crud App With Yii2

Hello,

[take in mind that I’m new to yii!]

I was trying to do the tutorial from here www.yiiframework.com/wiki/490/creating-a-simple-crud-app-with-yii2/ and I can’t access to gii.

For what I can speculate the file config/web.php code in the tutorial for gii settings is wrong according to:

github.com/yiisoft/yii2/blob/master/docs/guide/gii.md#basic-application

What I’m missing to get gii running and be able to complete the tutorial?

Thanks in advance.

Could you post the error trace?

I’m seeing the bootstrap 404 page:




Not Found (#404)


Unable to resolve the request "".

The above error occurred while the Web server was processing your request.


Please contact us if you think this is a server error. Thank you.



My web config says (relevant part):




        // Modules

        'modules' => array(

            'debug' => 'yii\debug\Module',

            'gii' => [

    			'class' => 'yii\gii\Module',

    			'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*'] // adjust this to your needs

],

        ),


        // Extra Params if we want them

        'params' => array()

    );



How have you installed gii?

Have you done this with composer install?

Are you testing on the same environment you did the composer install on? (eg when you are using ftp)

If not? Have you deployed all new files to you test environment?

I think this does look fine. If the IP would be wrong you would get a 403.

Exactly to which file have you added this config?

The common config or the config of your application?

[list=1]

[*]Do a composer update in case you have an old yii install.

[*]I would in fact suggest you to try install a fresh yii app and test if you can load gii. If this works, the config settings in your app are outdated (I suspect the changed composer extensions settings in yii could be a reason). Try to work and compare settings with this new app and your existing one.

[/list]

-Done a composer update without any visibles changes.

-I’ve tried a basic CRUD yii install with command: composer create-project --stability=dev yiisoft/yii2-app-basic basic from : http://www.yiiframework.com/wiki/568/create-crud-with-yii2/

and gii is working like a charm.

Then perhaps the problem is with the manual install that uses this tutorial: http://www.yiiframework.com/wiki/490/creating-a-simple-crud-app-with-yii2/

I’ll compare with the basic web estructure for finding the diferences…

Thanks and regards.

Great. Just check the config files (for example… the extensions.php getting loaded) … it maybe different… anyway… post your findings.

The web.php are differnt. The one in the bàsic file seems more evoluted and not compatible.

Check this:




<?php


$params = require(__DIR__ . '/params.php');


$config = [

        'id' => 'basic',

        'basePath' => dirname(__DIR__),

        'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'),

        'components' => [

                'cache' => [

                        'class' => 'yii\caching\FileCache',

                ],

                'user' => [

                        'identityClass' => 'app\models\User',

                        'enableAutoLogin' => true,

                ],

                'errorHandler' => [

                        'errorAction' => 'site/error',

                ],

                'mail' => [

                        'class' => 'yii\swiftmailer\Mailer',

                ],

                'log' => [

                        'traceLevel' => YII_DEBUG ? 3 : 0,

                        'targets' => [

                                [

                                        'class' => 'yii\log\FileTarget',

                                        'levels' => ['error', 'warning'],

                                ],

                        ],

                ],

                'db' => [

                        'class' => 'yii\db\Connection',

                        'dsn' => 'mysql:host=localhost;dbname=yf2',

                        'username' => 'root',

                        'password' => 'mypass',

                        'charset' => 'utf8',

                ],

        ],

        'params' => $params,

];


if (YII_ENV_DEV) {

        // configuration adjustments for 'dev' environment

        $config['preload'][] = 'debug';

        $config['modules']['debug'] = 'yii\debug\Module';

        $config['modules']['gii'] = 'yii\gii\Module';

}


if (YII_ENV_TEST) {

        // configuration adjustments for 'test' environment.

        // configuration for codeception test environments can be found in codeception folder.


        // if needed, customize $config here.

}


return $config;




And the one in the tutorial:




<?php

    return array(

        'id' => 'app',


        // Preload the Debug Module

        'preload' => array(

            'debug'

        ),


        'basePath' => dirname(__DIR__),

        'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'),


        // Components

        'components' => array(

            // UrlManager

            'urlManager' => array(

                'class' => 'yii\web\UrlManager',


                // Disable index.php

                'showScriptName' => false,


                // Disable r= routes

                'enablePrettyUrl' => true

            ),


            // Caching

            'cache' => array(

                'class' => 'yii\caching\FileCache'

            ),


            // UserIdentity

            'user' => array(

                'identityClass' => 'app\models\User',

            ),


            // Logging

            'log' => array(

                'traceLevel' => YII_DEBUG ? 3 : 0,

                'targets' => array(

                    array(

                        'class' => 'yii\log\FileTarget',

                        'levels' => array('error', 'warning')

                    )

                )

            ),


            // Database

            'db' => array(

                'class' => 'yii\db\Connection',

                'dsn' => 'mysql:host=localhost;dbname=yf2',

                'username' => 'root',

                'password' => 'mypass',

                'charset' => 'utf8'

            )

        ),


        // Modules

        'modules' => array(

            'debug' => 'yii\debug\Module',

            'gii'   => 'yii\gii\Module'

        ),


        // Extra Params if we want them

        'params' => array()

    );



add this to your config/main.php


'modules' => $params['modules'],

and add this to your common/config/params.php


'modules' => [

        'gii' => [

            'class' => 'yii\gii\Module',

        ],

    ],

for me its working