How to use the controller action's parameters?

In the doc, it says that to bind a parameter, you have to do this:


public function actionWhatever( $category )



But then how you call this from the url, this way?


/controller/whatever?category=5

I tried that but didn’t work.

I’m used to do this with other MVC frameworks:

/controller/action/value1/value2/etc

And value1, value2 and etc are bound to the first 3 parameters of the action, no matter their names.

I think this can be achieved on Yii with urlManager, but how?

The trouble with /controller/action/value1/value2 comes if you only need to call controller/action/value2.

Just create your URLs using the URL Manager. From your view file:




echo $this->createUrl('whatever',array('category'=>'6'));

// OR

echo CHtml::link('Link text',array('whatever','category'=>6));



That should work for you. If you want to do something like /whatever/6 then you’ll need to look at URL routing.

in your view:


$this->createUrl('controller/whatever',array('category'=>5))

it will generate a url:


index.php?r=controller/whatever?category=5