2015-10-15 22:12:04 10365次浏览 7条回答 1 悬赏 20 金钱

我在web.php里美化Url

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,//隐藏index.php
    //'enableStrictParsing' => false,
    //'suffix' => '.html',//后缀,如果设置了此项,那么浏览器地址栏就必须带上.html后缀,否则会报404错误
    'rules' => [
        //'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ],
],

之前没加的时候 访问http://localhost/basic/web/index.php?r=gii是可以跳转到生成模型界面的,自从加了上面代码就一直在主界面,gii访问不了了
我试着去掉 'enablePrettyUrl' => true,就可以了
不知道什么原因??

最佳答案

  • bryson 发布于 2015-10-16 13:48 举报

    setting enablePrettyUrl = true

    a.Apache 設定 DocumentRoot 指向 "YourPath.../basic/web"
    a.在你的 網址填入 http://localhost/gii

    b.不然看你 DocumentRoot 都沒指向 自己打上 /basic/web
    b.在你的 網址填入 http://localhost/basic/web/gii

    7 条回复
    回复于 2015-10-16 15:17 回复

    http://localhost/basic/web/index.php?r=gii 改成 http://localhost/basic/web/index.php/gii 就可以了 谢谢

    回复于 2015-10-16 15:50 回复

    抱歉抱歉!! 我忘了我自葛把 index.php 給拿掉了!!
    有想拿掉 index.php 的話 請找 => .htaccess <==

    回复于 2015-10-16 16:29 回复

    这个我已经隐藏了

    回复于 2015-10-16 16:46 回复


    那應該 http://localhost/basic/web/index.php/gii or http://localhost/basic/web/gii 都要可以才對

    回复于 2015-10-27 21:47 回复

    问个问题 basic模板 model\User.php 没有实现\yii\web\IdentityInterface接口 看了老汉的视频访问http://localhost/basic/web/说会报错 可是我正常的啊 什么情况

    回复于 2015-10-28 10:04 回复

    看不懂你的問題是甚麼也!! 可以詳細一點嗎 哈哈

    回复于 2015-10-28 10:46 回复

    有联系方式吗 这里说不清

  • 回答于 2015-10-16 08:48 举报

    那就试试 http://localhost/basic/web/gii 估计不行;把web作为documentroot

    1 条回复
    回复于 2015-10-16 15:17 回复

    可以的 谢谢

  • 回答于 2015-10-16 10:46 举报
    'urlManager'=> [
        'enablePrettyUrl' => true
    ]
    
    //'enablePrettyUrl' => true :
    //DocumentRoot ../basic/web
    //http://localhost/gii
    
    //'enablePrettyUrl' => false :
    //http://localhost/basic/web/index?r=gii
    
    

    去看一下 yii2 documentaction 的介紹!!
    http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html#$enablePrettyUrl-detail

    enablePrettyUrl : 意思就是美化 URL
    如果為 true 則 URL 可以用路徑代表參數 反之
    如果為 false 是用參數代表路徑的方式

    1 条回复
    回复于 2015-10-16 12:20 回复

    那现在我的问题 应该如何破解

  • 回答于 2015-10-17 00:38 举报
    1. URL 美化设置, http://yinzhezq.blog.163.com/blog/static/164862890201581984113653
     'urlManager' => [
                'enablePrettyUrl' => true,
                'showScriptName' => false,
            ],
    
    2. 开启gii功能
        $config['bootstrap'][] = 'gii';
        $config['modules']['gii'] = [ 
            'class' => 'yii\gii\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '设置你浏览器主机的IP'],
        ];  
    
    
    3. 访问地址http://XXX/gii                      
       XXX表示访问首页的地址
    
    4. 原因:当启动gii模块的时候,会自动设置gii的美化URL访问规则
    vendor/yiisoft/yii2-gii/Module.php
    
        /** 
         * @inheritdoc
         */
        public function bootstrap($app)
        {   
            if ($app instanceof \yii\web\Application) {
                $app->getUrlManager()->addRules([
                    $this->id => $this->id . '/default/index',
                    $this->id . '/<id:\w+>' => $this->id . '/default/view',
                    $this->id . '/<controller:[\w\-]+>/<action:[\w\-]+>' => $this->id . '/<controller>/<action>',
                ], false);
            } elseif ($app instanceof \yii\console\Application) {
                $app->controllerMap[$this->id] = [ 
                    'class' => 'yii\gii\console\GenerateController',
                    'generators' => array_merge($this->coreGenerators(), $this->generators),
                    'module' => $this,
                ];  
            }   
        }   
    
    
    觉得很赞
  • 回答于 2015-12-28 15:39 举报

    可参考我的做法

    return [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'suffix' => '.html',
    ];
    

    这个时候直接访问http://localhost/gii.html就行

    , 觉得很赞
  • 回答于 2017-12-14 17:27 举报

    遇到同样问题,请问您当时是怎么解决的呢?

  • 回答于 2018-03-07 15:31 举报

    必须是 'xxx.../gii.html' 而不是'xxx.../gii' ,因为使用了'suffix' => '.html'

    觉得很赞
您需要登录后才可以回答。登录 | 立即注册
xyf90314
副总裁

xyf90314

注册时间:2015-03-04
最后登录:2023-03-13
在线时长:95小时23分
  • 粉丝21
  • 金钱5257
  • 威望40
  • 积分6607

热门问题