10

我下载了高级模板,将其解压缩并更改了后端和前端的根文档,但我似乎无法弄清楚如何让 Gii 工作以执行 crud 操作。

composer.JSON 中有 require 和 require-dev 字段,我在它们中都包含了 gii,并且每个都单独包含,但没有运气。

我还尝试通过 composer 获取模板,在安装时我看到 gii 已安装,但仍然无法使其工作。

这是我得到 Yii 模板的地方:https ://github.com/yiisoft/yii2-app-advanced

4

5 回答 5

21

这是如何让 Gii 从远程服务器工作以获取高级设置模板。

在前端配置文件中。例如:

/frontend/config/main-local.php

添加以下代码:

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' => ['*'],
    ];
}

array有趣的部分是经过修改的 Gii 。

于 2014-11-11T12:25:47.593 回答
11

第 1 步:将以下行添加到 composer.json 的 required-dev

"yiisoft/yii2-gii": "*"

第 2 步:更新您的作曲家。第 3 步:将以下行添加到您的 frontend/config/main.php 文件中。不要包括这些............

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

第 4 步:如果您启用了干净的 url,请转到

project_name/frontend/web/gii

如果没有,那就去

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

您可以点击链接yii2_gii

于 2014-06-10T10:28:46.257 回答
5

文档中所述,您必须调整/frontend/config/main-local.php中允许的 IP :

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

如果您已像这样修改/frontend/config/main.php以获得漂亮的 URL:

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

您可以使用 URL 调用 gii

    yourVM.local/gii

(让您的VM.local指向 Hosts 文件中的前端模块。)

于 2015-03-13T16:19:58.537 回答
2

另外,如果gii仍然不起作用,请尝试以下操作:

这应该被 yii 团队很好地记录下来!

在我使用init命令后,在 中/frontend/config/main-local.php,我发现:

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';
}

我的应用程序处于dev模式,并且上面的声明停止了我gii的工作,所以...评论该行

于 2014-11-07T19:43:42.677 回答
1

我不得不在相关配置文件的“组件”中注释掉 urlManager 元素(禁用漂亮的 Urls)(实际上默认情况下注释掉了)。

backend/config/main.php

在禁用漂亮的 Urls 之前,我可以加载 Gii 页面,但是当尝试加载任何生成器页面(控制器、模型等)时,我被重定向到主页。

于 2017-07-22T12:14:33.503 回答