php 让 Gii 在 Yii 2.0 上工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23102922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getting Gii to work on Yii 2.0
提问by tareq
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.
我下载了高级模板,将其解压缩并更改了后端和前端的根文档,但我似乎无法弄清楚如何让 Gii 工作来执行 crud 操作。
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.
在 composer.JSON 中有 require 和 require-dev 字段,我在它们两个中都包含了 gii 并且每个都单独包含了,但没有运气。
i also tried getting the template through composer, and while installing i saw gii as installed, but still could not get it to work.
我也尝试通过 composer 获取模板,在安装时我看到 gii 已安装,但仍然无法让它工作。
this is where i got my Yii template: https://github.com/yiisoft/yii2-app-advanced
这是我得到 Yii 模板的地方:https: //github.com/yiisoft/yii2-app-advanced
回答by girish
This is how to get Gii working from a remote server for an advanced setup template.
这是如何让 Gii 从远程服务器工作以获取高级设置模板。
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.
有趣的部分是array
经过修改的 Gii 。
回答by Kshitiz
Step 1: Add Following line to required-dev of composer.json
第 1 步:将以下行添加到 composer.json 的 required-dev
"yiisoft/yii2-gii": "*"
Step 2: Update your composer. Step 3: Add Following line to your frontend/config/main.php file. Don't incude these ..........
第 2 步:更新您的作曲家。第 3 步:将以下行添加到您的 frontend/config/main.php 文件中。不要包括这些…………
'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
第 4 步:如果您启用了干净的 url,则转到
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
您可以按照链接yii2_gii
回答by Mischa
Like described in the Docsyou have to adjust the allowed IPs in the /frontend/config/main-local.php:
就像文档中描述的那样,您必须在/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.*.*']
];
}
If you have modified your /frontend/config/main.phplike this for pretty URLs:
如果您像这样修改了/frontend/config/main.php以获得漂亮的 URL:
return [
...
'components' => [
...
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false
],
...
];
You can call gii with the URL
您可以使用 URL 调用 gii
yourVM.local/gii
(Having yourVM.localpoint to your Frontend Module in your Hosts file.)
(让yourVM.local指向 Hosts 文件中的前端模块。)
回答by Ionut Flavius Pogacian
Also, try this if gii
still does not work:
另外,如果gii
仍然不起作用,请尝试此操作:
This should be well documented by the yii team!
yii 团队应该很好地记录了这一点!
After I used the init
command, in /frontend/config/main-local.php
, I found:
在我使用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';
}
My app is in dev
mode, and te above declaration, stops my gii
to work, so ... comment that line
我的应用程序处于dev
模式,并且上面的声明停止了我gii
的工作,所以...注释该行
回答by Brent Self
I had to comment out the urlManager element (disabling pretty Urls) in 'components' in the relevant config file (actually commented out by default).
我不得不在相关配置文件的“组件”中注释掉 urlManager 元素(禁用漂亮的 Urls)(实际上默认情况下已注释掉)。
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.
在禁用漂亮的 URL 之前,我可以加载 Gii 页面,但是在尝试加载任何生成器页面(控制器、模型等)时,我被重定向到主页。