arbiterx
(Arbiterx)
February 4, 2010, 8:26am
1
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¶m2=22222’);
Could anybody give me some advice?
Onman
(O Rijkers)
February 4, 2010, 10:17am
2
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¶m2=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.
arbiterx
(Arbiterx)
February 4, 2010, 10:30am
3
Onman:
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.
andy_s
(Arekandrei)
February 4, 2010, 11:30am
4
You can add additional parameters to the $_GET array
zillabyte
(Zillabyte)
April 17, 2010, 4:42pm
6
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.
zillabyte:
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