2014-10-19 24 views

回答

1

您可以在config中使用url規則中的變量;

'<category>/<seo>'=>'soru/goster' 

然後在你的控制器(我改名爲我你不發表您的控制器;

public function actionGoster($seo) //you can also access $category 
{ 
    if (isset($seo)) 
    { 
    //do your lookup 
    } 
} 

訪問的URL像這樣;

http://yourDomain/index.php/CATEGORY/SEO/ 

我這樣做在數據庫中查找允許SEO友好的網址的項目;

'plants/<name>'=>'catalog/viewSingle' 

控制器;

public function actionViewSingle($name) 
{ 
    if (isset($name)) 
    { 
     $model = Plant::model()->findByAttributes(array('url_name'=>$name)); 

     if ($model) 
     { //do stuff } 
     else 
     { 
     //do matches and find similar plants that has these characters... 
     $this->render('error_matches', array('matches'=>$matches)); 
     } 
    } 
    else 
    { 
     //404 
    } 

編輯:

爲了避免所有URL去這個確保您有默認的規則;

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

它會影響到「網站/約,網站/接觸」。現在,它不工作,breadcumb開始出現問題:■錯誤:「元素需要爲每個鏈接‘’的」標籤 – Serhat 2014-10-19 11:39:37

+0

確保缺省規則存在(''=>' /'),因爲它們是必需的。也可以嘗試將它放置在默認值的上方和下方並對其進行測試。 – 2014-10-19 11:46:45

+0

這是。這是工作。非常感謝 :) – Serhat 2014-10-19 12:00:30

相關問題