2015-03-06 10:49:36 4287次浏览 0条回答 0 悬赏 0 金钱

使用basic应用程序模板,config/web.php配置:

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            // 'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                ['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
            ],
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '3dLi9CE_OQPi8lTN2ZK5BPR2lbd4f71r',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
    ],
    'params' => $params,
];

web/.htaccess 文件:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

nginx 配置:

server {
        listen 80;
        server_name localhost;
        root /home/wwwroot/basic;
        index index.php index.html index.htm;
        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location / {
                try_files $uri $uri/ /index.php?$args;
        }
}

访问:http://localhost/users
页面出现 No input file specified.

而且这样设置了'enablePrettyUrl' => true 后,访问:http://localhost/web/index.php?r=site/login 或者 http://localhost/web/index.php?r=site/about 等等其他操作时,显示的都是首页的内容;访问:http://localhost/web/site/login 或者 http://localhost/web/site/about 等等操作时,页面也是显示 No input file specified.

'enablePrettyUrl' => false 的话显示正常,哪位朋友知道代码有哪个地方错误了,已经调试了一天了。。。

yii版本:2.0.3

补充于 2015-03-06 14:24

原来nginx目录一定要设置basic/web,nginx配置文件:

root /home/wwwroot/basic;

改为

root /home/wwwroot/basic/web;

访问地址为:
http://localhost/users
http://localhost/site/login

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
dzgrief
助理

dzgrief

注册时间:2015-03-05
最后登录:2015-04-13
在线时长:8小时51分
  • 粉丝0
  • 金钱55
  • 威望0
  • 积分135

热门问题