yii2的gii到底怎么配置可以开始用啊? [ 2.0 版本 ]
官方文档上说的:Gii 是 Yii 中的一个模块。可以通过配置应用的 yii\base\Application::modules 属性开启它。通常来讲在 config/web.php 文件中会有以下配置代码:
$config = [ ... ];
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
这段配置表明,如果当前是开发环境,应用会包含 gii 模块,模块类是 yii\gii\Module。
如果你检查应用的入口脚本 web/index.php,将看到这行代码将 YII_ENV_DEV 设为 true:
defined('YII_ENV') or define('YII_ENV', 'dev');
鉴于这行代码的定义,应用处于开发模式下,按照上面的配置会打开 Gii 模块。你可以直接通过 URL 访问 Gii:
http://hostname/index.php?r=gii
这些配置它本身就有,而且我现在就是用本机访问,也不用去添加ip地址的设置,可是为什么我什么都没有,是不是要在哪里配置的?
最佳答案
其他 5 个回答
-
你检查一下,你的gii模块代码是否存在,不存在的话,去下载一个呗,
共 2 条回复怎么看gii模块代码是否存在哒,是在vendor/yiisoft/yii2-gii下的Module.php吗?
/** * This is the main module class for the Gii module. * * To use Gii, include it as a module in the application configuration like the following: * * ~~~ * return [ * 'bootstrap' => ['gii'], * 'modules' => [ * 'gii' => ['class' => 'yii\gii\Module'], * ], * ] * ~~~ * * Because Gii generates new code files on the server, you should only use it on your own * development machine. To prevent other people from using this module, by default, Gii * can only be accessed by localhost. You may configure its [[allowedIPs]] property if * you want to make it accessible on other machines. * * With the above configuration, you will be able to access GiiModule in your browser using * the URL `http://localhost/path/to/index.php?r=gii` * * If your application enables [[\yii\web\UrlManager::enablePrettyUrl|pretty URLs]], * you can then access Gii via URL: `http://localhost/path/to/index.php/gii` * * @author Qiang Xue <qiang.xue@gmail.com> * @since 2.0 */
那个php文件里这段话是注释的,我有试过把那段return部分的注释去掉,可是还是没能直接输入那个url打开gii的那个页面
-
gii配置中能修改的属性好像就只有这些了:
/** * @inheritdoc */ public $controllerNamespace = 'yii\gii\controllers'; /** * @var array the list of IPs that are allowed to access this module. * Each array element represents a single IP filter which can be either an IP address * or an address with wildcard (e.g. 192.168.0.*) to represent a network segment. * The default value is `['127.0.0.1', '::1']`, which means the module can only be accessed * by localhost. */ public $allowedIPs = ['127.0.0.1', '::1']; /** * @var array|Generator[] a list of generator configurations or instances. The array keys * are the generator IDs (e.g. "crud"), and the array elements are the corresponding generator * configurations or the instances. * * After the module is initialized, this property will become an array of generator instances * which are created based on the configurations previously taken by this property. * * Newly assigned generators will be merged with the [[coreGenerators()|core ones]], and the former * takes precedence in case when they have the same generator ID. */ public $generators = []; /** * @var integer the permission to be set for newly generated code files. * This value will be used by PHP chmod function. * Defaults to 0666, meaning the file is read-writable by all users. */ public $newFileMode = 0666; /** * @var integer the permission to be set for newly generated directories. * This value will be used by PHP chmod function. * Defaults to 0777, meaning the directory can be read, written and executed by all users. */ public $newDirMode = 0777;
阿星
注册时间:2015-07-20
最后登录:2017-01-18
在线时长:7小时1分
最后登录:2017-01-18
在线时长:7小时1分
- 粉丝5
- 金钱245
- 威望0
- 积分315