简体   繁体   中英

Yii can't start gii

I am developing website with PHP Yii Framework and I am now stack, I need to start gii, but I can't do this. when i type www.example.com/index.php/gii or www.example.com/gii it gives me this error :

    /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.

I don't think that the error is because of modified htaccess and main configuration, but anyway here is main.php configuration file:

    '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>',
        ),
    ),

and .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]

So can you help me, please?

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

Also check urlManager 's rules . That was the issue for me:

'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>',
            // ...
        ),
     ),
 ),

Like FelikZ mentioned , this might be because you have created a third param in a rule that uses \\w+ instead of the default \\d+ and hence will match "gii" as the controller, "default" as the action and "login" as the ID (or sub action, or whatever is mentioned).

My rules looked like the following:

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

The fix is to add the following as the very first rule in order to make gii hit the right place:

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

Which should make your entire urlManager config look something like the following:

'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>',
    ),
),

Check if the gii module in your configuration file is there and it is uncommented. If gii is not in there you should add it within the module array.

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

More info for gii here

This problem occurs because of the two sessions of the OP, for example cookie PHPSESSID there two domains domain .site.ru and admin.site.ru two different sessions. Delete PHPSESSID cookies and login to gii

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM