2013-12-19 18 views
2

這是我的網址:我想自定義警予URL

http://localhost/techsupportscam/index.php/question/search/2?category=XP+Support

現在我想轉換爲這樣的事情:

http://localhost/techsupportscam/index.php/question/search/2/XP+Support

我的控制器是question和方法search

我的鏈接是:

<?php echo Yii::app()->createUrl('question/search/',array('id'=>$subCategory->id,'category'=>$subCategory->title)); ?>">

我怎樣才能做到這一點?你們能幫我嗎?

感謝

+2

改寫'配置/​​ main.php'網址經理。檢查http://stackoverflow.com/questions/17503041/email-verification-in-yii-framework?rq=1 –

+0

我已經取消了我的URL管理器代碼config.php –

+0

在你的案例規則可能就像 ' <控制器:\ W +>/// // '=>' ///' 只需檢查。並使用'.htaccess'如果你不明白。 –

回答

2

你可以做到這一點,因爲這對通過CUrlManager規則,

'rules' => array(
       'question/search/<id:\d+>/<category>/*' => 'question/search', 

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

爲什麼你使用了'。*?>'? –

+0

你可以這樣做'question/search///*'也是! –

+1

我有這個問題嗎?現在someKey/someValue會像問題/搜索/ / /someKey/someValue/...* –

1

爲此,您可以從應用程序配置文件的urlManager規則。 在規則數組中添加此波紋線。

文件路徑:保護/配置/ main.php

'urlManager' => array(
     'urlFormat' => 'path', 
     'rules' => array(
      '<controller:\w+>/<action:\w+>/<category:([^~,]+)>' => '<controller>/<action>', 
      ........... 
      ...........