Yii中的Url Manager问题

时间:2014-07-25 09:44:22

标签: php regex yii url-routing yii-url-manager

我遵循网址规则:

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

对于rescuetraining控制器,我有不同的网址http://strutmymutt.com/training/life-rewardshttp://strutmymutt.com/training/sit,但最后一个&#34; training/sit&#34;不管用。我尝试了很多不同的方法。如果我添加一些东西&#34; - &#34;然后坐下来和其他人一起工作。

1 个答案:

答案 0 :(得分:0)

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

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

我还强烈建议您将这些默认的catch-all规则移到数组的底部/末尾:

'<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而不是因为找不到该控制器文件。确保这些通用规则放在数组的底部/末尾。

相关问题