Pass variable to create action using url

Hi,

I have question. I suddenly have an issue that I can not explain.

I have a controller with a bunch of actions. I want to create a new record and I use the create function that was generated by Gii. I want to add a variable to the function. So I do this:




public function actionCreate($category_id)

{ 

  //function is stripped.

}



I open the url using /category/create/4. 4 is the category id. This doesn’t seem to work. I get an 400 error and it says it’s missing the category_id is missing. If I change $category_id to $id it works. However, the update function, etc. also have a $category_id variable and that does work too.

So, who can explain to me why the $category_id does not work in the create function, but does in the update function?

Best regards.

P.s. i have seo friendly url’s set.

I guess your url rule for this is:


'category/create/<id:\d+>' => 'category/create',

instead of


'category/create/<category_id:\d+>' => 'category/create',

Have u used urlrules in ur config file

if yes then checked that and also refer this

copy paste ur updateaction code.

Thanks guys. It was in deed the routing that was not good. It’s solved now.