Galang Re
Galang Re

Reputation: 224

How to send data from controller to another controller in yii2

Can i get data that i got from controller, and then send it to another controller (in the same folder) in Yii2?

this is my SiteController:

public function actionIndex()
{
...
 $data = Yii::$app->request->post();
 $reg_res = $data['ColoringForm']['region'];
...

i want to send $reg_res to my DataController:

 public function actionShowdata()
{
$reg_res ??

how can i do this?

Upvotes: 0

Views: 3138

Answers (2)

Simon Tong
Simon Tong

Reputation: 410

You can use the following to run a separate action within the same request:

Yii::$app->runAction('controller/show-data', ['param1'=>'value1', 'param2'=>'value2']);

Upvotes: 0

Sunil kumar
Sunil kumar

Reputation: 771

Post array data is not possible to send from on controller to another controller but you can send it through parameters.

Try below code

$this->redirect(array('controller/action', 'param1'=>'value1', 'param2'=>'value2',...)

Upvotes: 1

Related Questions