Yii can';不要启动gii


Yii can't start gii

我正在用PHP Yii框架开发网站,我现在是堆栈,我需要启动gii,但我做不到。当我键入www.example.com/index.php/gii或www.example.com/gii时,会出现以下错误:

    /gii/default/login // <- website redirects to here
    This webpage has a redirect loop
    The webpage at http://www.example.com/gii/default/login has resulted in too many redirects.
Clearing your cookies for this site or allowing third-party cookies may fix the problem. 
If not, it is possibly a server configuration issue and not a problem with your computer.

我不认为这个错误是因为修改了htaccess和主配置,但无论如何,这里是main.php配置文件:

    'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'rules'=>array(
            'site/page/<view:'w+>'=>'site/page',
            '<controller:'w+>/<cact:'w+>/<action:'w+>'=>'<controller>/<cact>',
            '<controller:'w+>/<id:'d+>'=>'<controller>/view',
            '<controller:'w+>/<action:'w+>/<id:'d+>'=>'<controller>/<action>',
            '<controller:'w+>/<action:'w+>'=>'<controller>/<action>',
        ),
    ),

和.htaccess:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
#non-www to www
RewriteCond %{HTTP_HOST} !^www'.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule ^.*$ /index.php [L]

你能帮我吗?

要使用此路径:index.php?r=gii/default/login,必须关闭/protected/config/main.php 中的url管理器

同时检查urlManagerrules。这就是我的问题:

'components' => array(
    'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false,
        'rules' => array(
            // ...
            // will handle `gii/default/login` uri and makes infinite redirection loop circle
            '<controller:'w+>/<action:'w+>/<sub_action:'w+>'=>'<controller>/<action>',
            // ...
        ),
     ),
 ),

检查配置文件中的gii模块是否存在并且未注释。如果gii不在其中,则应将其添加到模块阵列中。

'modules'=>array(
    'gii'=>array(
        'class'=>'system.gii.GiiModule',
        'password'=>***choose a password***
    ),
),

有关gii的更多信息,请点击此处

就像FelikZ提到的那样,这可能是因为您在使用'w+而不是默认'd+的规则中创建了第三个参数,因此将匹配"gii"作为控制器,"default"作为操作,"login"作为ID(或子操作,或任何提到的)。

我的规则如下:

'<controller:'w+>/<action:'w+>/<id:'w+>'=>'<controller>/<action>',
'<controller:'w+>/<action:'w+>'=>'<controller>/<action>',

修复方法是添加以下内容作为第一条规则,以使gii命中正确的位置:

'gii/<controller:'w+>/<action:['w-]+>' => 'gii/<controller>/<action>',

这将使您的整个urlManager配置看起来像以下内容:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'rules'=>array(
        'gii/<controller:'w+>/<action:['w-]+>' => 'gii/<controller>/<action>',
        '<controller:'w+>/<action:'w+>/<id:'w+>'=>'<controller>/<action>',
        '<controller:'w+>/<action:'w+>'=>'<controller>/<action>',
    ),
),

这个问题的出现是因为OP的两个会话,例如cookie PHPSSID有两个域domain.site.ru和admin.site.ru两个不同的会话。删除PHPSSID cookie并登录gii