2013-07-30 62 views
0
<?php echo CHtml::link($value->title, array(Yii::app()->createUrl('forum/thread', array('id'=>$value->thread_id)))); ?> 

我得到一個鏈接如何在Yii框架中編寫URL規則?

論壇/線程/ 2

在我urlManager規則'thread/<id:\d+>' => 'forum/thread',

如何更改規則和方法createUrl?

createUrl('any-value/forum/thread', array('id'=>$value->thread_id)) 

在URL獲得

論壇/任何價值/線程/ 2或論壇/ PHP換新手/線程/ 2

我爲我的英語很抱歉,非常感謝

回答

0

URL Manager規則應該是這樣的:

'forum/<title:\w+>/thread/<id:\d+>' => 'forum/thread', //make sure this is listed first so it has priority 
'thread/<id:\d+>' => 'forum/thread', 

然後在你的控制器中你會有這樣的:

public function actionThread($id,$title=null) { 
    //$title will contain title from url if sent 
} 
0

試試這個: 'forum/any-value/thread/<id:\d+>' => 'any-value/forum/thread',

與此: createUrl('any-value/forum/thread', array('id'=>$value->thread_id)) 所以你應該得到forum/any-value/thread/2

應該工作!

但如果你是叫forum在模塊內部,那麼你會做這樣的:

'any-value/thread/<id:\d+>' => 'any-value/forum/thread',

以及與此: createUrl('any-value/forum/thread', array('id'=>$value->thread_id))