Yii2.0----配置文件设置路由、gii

一、美化URL

我们没有配置URL的时候访问controllers下面的siteController的say方法

http://hostname/index.php?r=site/say&message=Hello+World

配置之后URL就会简化很多

http://hostname/site/say

配置如下;在config/web.php文件里面,在component属性里面增加如下

 'urlManager' => [
            'enablePrettyUrl' => true,  //美化url==ture
            'enableStrictParsing' => true,  //启用严格解析 
            'showScriptName' => false,   //隐藏index.php
            'rules' => [
               ['class' => 'yii
estUrlRule','controller' => 'user', 'pluralize'=>FALSE],
            ],
        ]

配置以上信息之后若路径访问有问题,那你可以检查一下/etc/nginx.sites-enabled文件夹下面你配置的站点信息,里面是否加了rewrite

server {
        listen       80;
        server_name  new.com ;
        location / {
            root   F:/www/new/web;
            index  index.html index.htm index.php;
            #autoindex  on;
             if (!-e $request_filename){
                rewrite ^/(.*) /index.php?r=$1 last;
            }
        }
        location ~ .php$ {
            root          F:/www/new/web;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

二、配置Gii

开始我的allowedIPs是没有192.168.44.*的,所以我没有访问gii的权限,加上之后就可以访问了,加上我上面做了URL美化,所以我只需要在我配置的域名后面加上/gii就可以进入gii页面了

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yiigiiModule',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.44.*'],
    ];
}
原文地址:https://www.cnblogs.com/humiao-0626/p/13150901.html