2014-07-25 36 views
0

我下面的URL規則:地址管理問題的Yii

'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控制器,我有不同的URL http://strutmymutt.com/training/life-rewardshttp://strutmymutt.com/training/sit,但最後一個「training/sit」是行不通的。我嘗試了很多不同的方式。如果我添加一些「 - 」坐下來,然後一些字符正在工作。

回答

1

只需將此規則移動到的所有其他規則

'<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,因爲它找不到那個控制器文件。確保像這些一般規則放置在數組的底部/末尾。