How to get parameter in action by forward function.

I want to forward to another controller’s action.But now I cant pass parameters.

This is ok.

$this->getController()->forward(‘MyController/MyAction/’);

This will be wrong.

$this->getController()->forward(‘MyController/MyAction?param1=1111&param2=22222’);

Could anybody give me some advice?

You are trying to do a redirect.

The forward function does not change the requested Url, but it just executes some code belonging to another controller/action.

But I don’t want to change the url.So I can’t use redirect.

You can add additional parameters to the $_GET array :)

Thank you very much!

I had this same issue but wanted to use the getController and Render method to pass the variables. From inspecting the CWebApplication source this is what I came up with.





$data = [mydatasomewhere];


if(($ca=Yii::app()->createController('mycontroller'))!==null){

  list($controller,$actionID)=$ca;

  $controller->init();

  $controller->render('myview',array(

      'data'=>$data,

      ));

}




Basically, this uses the CWebApplication instance to create a specified controller. If successful, then it populates new vars with the controller and actions. You then have a valid instance of the controller you want and can use it like you normally would. This looks like a better approach then adding params to the _GET array.

Interesting solution, though it would use more resources than simply appending to $_GET