-1

我尝试使用 yii 框架制作网站,并制作友好的网址。如果我使用友好的网址,例如:

http://localhost/eshops/     -> calls protected/controllers/SiteController->actionIndex()
http://localhost/eshops/login -> calls protected/controllers/SiteController->actionLogin()
http://localhost/eshops/logout -> calls protected/controllers/SiteController->actionLogout()
 ...

但是如何使用另一个控制器 AbcController

http://localhost/eshops/abc/a -> calls protected/controllers/AbcController->actionA()
http://localhost/eshops/abc/b -> calls protected/controllers/AbcController->actionB()

它不显示“错误404”?

.htaccess 是

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

规则在 protected/config/main.php

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

谢谢

4

1 回答 1

1

您需要记住执行规则的顺序!您只需要设置正确的规则顺序

'rules'=>array(
        'gii'=>'gii',
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        '<action:(login|logout|register|contact)>' => 'site/<action>',
//      or full access 
//      '<action:\w+>' => 'site/<action>',
    ),
于 2012-11-17T16:38:48.277 回答