getting Gii to work on Yii 2.0
Asked Answered
D

5

11

i downloaded the advanced template, extracted it and changed the root documents for the back-end and the front-end, but i can't seem to figure out how to get Gii working to perform the crud operations.

there is require and require-dev field in the composer.JSON i included gii in both of them and each one separately with no luck.

i also tried getting the template through composer, and while installing i saw gii as installed, but still could not get it to work.

this is where i got my Yii template: https://github.com/yiisoft/yii2-app-advanced

Dysuria answered 16/4, 2014 at 7:37 Comment(4)
and how do you call gii? it must work by default.Vinnievinnitsa
Did you solve this? I have the exact same issue. The only difference is I installed everything via composer.Conformance
@Conformance yes i did, i'm sorry i did not provide an answer. i had this 'modules' => ['gii' => 'yii\gii\Module'], missing from my backend/config/main.php. my project is in backend, if yours is somewhere else put this accordingly.Dysuria
What's the error you get? Can you open gii? Is the CRUD generator the only stuff which is not working? Are you accessing it from localhost?Amyamyas
C
21

This is how to get Gii working from a remote server for an advanced setup template.

In the frontend config file. For example:

/frontend/config/main-local.php

Add the following code:

if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

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

The interesting part is the Gii array which has been modified.

Creature answered 11/11, 2014 at 12:25 Comment(2)
i have doen this but i keep getting Invalid Configuration – yii\base\InvalidConfigException The configuration for the "bootstrap" component must contain a "class" element.Papacy
@bonez Can you paste your config file?Creature
S
11

Step 1: Add Following line to required-dev of composer.json

"yiisoft/yii2-gii": "*"

Step 2: Update your composer. Step 3: Add Following line to your frontend/config/main.php file. Don't incude these ..........

  'modules' => [
    ............
    'gii' => [
      'class' => 'yii\gii\Module', //adding gii module
      'allowedIPs' => ['127.0.0.1', '::1']  //allowing ip's 
    ],
    ...........
  ]

Step 4: If you have enabled your clean url then go to

project_name/frontend/web/gii

if not then go to

project_name/frontend/web/index.php?r=gii

You can follow the link yii2_gii

Spoils answered 10/6, 2014 at 10:28 Comment(2)
i have doen this but i keep getting Invalid Configuration – yii\base\InvalidConfigException The configuration for the "modules" component must contain a "class" element.Papacy
When you generated you application before or after the yii2 release?Spoils
A
6

Like described in the Docs you have to adjust the allowed IPs in the /frontend/config/main-local.php:

    if (!YII_ENV_TEST) {
      ...
      $config['bootstrap'][] = 'gii';
      $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.*.*']
      ];
    }

If you have modified your /frontend/config/main.php like this for pretty URLs:

    return [
    ...
    'components' => [
      ...
      'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false
      ],
      ...
    ];

You can call gii with the URL

    yourVM.local/gii

(Having yourVM.local point to your Frontend Module in your Hosts file.)

Aixlachapelle answered 13/3, 2015 at 16:19 Comment(0)
Z
2

Also, try this if gii still does not work:

This should be well documented by the yii team!

After I used the init command, in /frontend/config/main-local.php, I found:

if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

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

My app is in dev mode, and te above declaration, stops my gii to work, so ... comment that line

Zenia answered 7/11, 2014 at 19:43 Comment(0)
T
1

I had to comment out the urlManager element (disabling pretty Urls) in 'components' in the relevant config file (actually commented out by default).

backend/config/main.php

Before disabling pretty Urls I could load the Gii page, but when attemtping to load any of the generator pages (Controller, Model, etc.) I was redirected to the home page.

Tague answered 22/7, 2017 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.