Question

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

i got a link

forum/thread/2

in my urlManager rules 'thread/<id:\d+>' => 'forum/thread',

how to change the rule and method createUrl?

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

to get in url

forum/any-value/thread/2 or forum/php-for-newbies/thread/2

I am sorry for my english, thanks a lot

Was it helpful?

Solution

URL Manager rule should look like this:

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

Then in your controller you would have this:

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

OTHER TIPS

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

and with this: createUrl('any-value/forum/thread', array('id'=>$value->thread_id)) So you should get forum/any-value/thread/2

that should work!

But If you are inside the module called forum then you would do like that:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top