0

我遵循网址规则:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'rules'=>array(
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        'rescues/rescueprofile/<id:\d+>'=>'rescues/rescueprofile',
     // '<controller:\w+>/<breed:\w+>'=>'<controller>/view',
        '/breeds/<breed:[^\/]+>' => 'breeds/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

        'rescues/learn/<param1:\w+>'=>'rescues/learn',
        'breeds/<breed:\w+>'=>'breeds/view',
        'rescues/rescueprofile/<id:\d+>'=>'rescues/rescueprofile',
        'rescues/createadoptapplication/<id:\d+>'=>'rescues/createadoptapplication',
        'rescues/viewapplication/<id:\d+>'=>'rescues/viewapplication',
        'rescues/editdog/<id:\d+>'=>'rescues/editdog',
        'rescues/updateinfo/<name:\w+>'=>'rescues/updateinfo',
        'training'=>'rescuetraining',
        '<training:\w+>/<id:[a-zA-Z0-9 -]+>'=>'rescuetraining/view/<id:\w+>',
        'login'=>'site/login'
    ),

对于救援训练控制器,我有不同的网址http://strutmymutt.com/training/life-rewardshttp://strutmymutt.com/training/sit但最后一个“ training/sit”不起作用。我尝试了很多不同的方法。如果我添加一些“-”来坐和一些字符,那么它就可以工作了。

4

1 回答 1

0

只需将此规则移至所有其他规则的顶部

'<training:\w+>/<id:[a-zA-Z0-9 -]+>'=>'rescuetraining/view/<id:\w+>',

我还强烈建议您将这些默认的包罗万象的规则移到数组的底部/末尾:

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

解释:

training/sit将首先匹配此规则:

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

但是,您没有调用控制器,其中包含名为trainingController的操作sitAction()。Yii 会抛出 404,因为它找不到那个控制器文件。确保将此类一般规则放置在数组的底部/末端。

于 2014-07-25T10:35:38.420 回答