2015-07-21 15:00:26 32417次浏览 6条回答 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地址的设置,可是为什么我什么都没有,是不是要在哪里配置的?

最佳答案

  • koko 发布于 2015-07-21 15:55 举报

    把你的域名换成127.0.0.1试试

    6 条回复
    回复于 2015-07-21 16:06 回复

    换了还是什么都没,我现在把一切又回到了最原始的,所以可以麻烦你和我说下一步一步要怎么设置吗?我现在不明白它到底要不要设置了,看文档它好像是说直接输那个url就能出来那个页面的,可是我的是什么都没出来,就白白的一个页面,连错误信息什么的都没。

    回复于 2015-07-21 16:10 回复

    哦哦,行了行了,换成127.0.0.1就直接好了,刚一不小心把127.0.0.1后面的漏掉才不行的,谢谢你啦~~这个问题终于解决了,啊,好开心呀。嘿嘿。

    回复于 2016-04-19 23:44 回复

    为什么我的还是不行呢??楼主怎么解决的

    回复于 2016-04-19 23:47 回复

    原来是我自己配置了'urlManager' => [

            'showScriptName' => true,
            'enablePrettyUrl' => true
        ],导致http://hostname/index.php?r=gii这样访问不到。有个问题,为什么设置了urlManager后url会不兼容默认的
    
    回复于 2016-04-20 10:02 回复

    gii模块仅限本地访问,默认得用127.0.0.1或者localhost地址.

    回复于 2017-05-16 11:35 回复

    用了url美化之后,应该怎样设置才能访问到gii模块呢?

  • 回答于 2015-07-21 15:21 举报

    你检查一下,你的gii模块代码是否存在,不存在的话,去下载一个呗,

    2 条回复
    回复于 2015-07-21 15:51 回复

    怎么看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的那个页面

    回复于 2018-05-24 14:38 回复

    你最后是咋样解决这个问题的呀大哥

  • 回答于 2015-07-23 10:43 举报

    默认的Gii只能通过127.0.0.1来访问,也就是本机访问,安全~

  • 回答于 2016-05-09 21:51 举报

    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;
    
    , 觉得很赞
  • 回答于 2017-07-11 13:35 举报

    我都照上面设置了还是不能访问gii模块,是什么原因啊?

  • 回答于 2017-10-13 15:31 举报

    'allowedIPs' => ['*'],

您需要登录后才可以回答。登录 | 立即注册
阿星
见习主管

阿星

注册时间:2015-07-20
最后登录:2017-01-18
在线时长:7小时1分
  • 粉丝5
  • 金钱245
  • 威望0
  • 积分315

热门问题