Action Parameters

I have a controller with actions.

I want to pass parameters to the actions via url

website/index.php/controller/myaction/param

The param is just going to be a number or short string.

If I declare an action in the controller:

public function actionMyaction( $id )

Yii hands me the param nicely,

But if someone does

website/index.php/controller/myaction/

without a parameter I get a 404.

What’s the most Yii appropriate and graceful way to route that to a particular view rather than it ending up in a 404?

At first I thought invalidActionParams but I don’t understand the very brief description given on the docs page for that function.

Hi Phil

check this


public function actionMyaction($id=null) {


if ($id==null) {

//code without id param

} else {

//code with id param

}




}