0

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?

2 Answers 2

1

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',...)
Sign up to request clarification or add additional context in comments.

5 Comments

i am newbie in yii2.. can you help me how to implement it in my code?
is that possble to send data without redirect to another page? i mean just send the data
You will get the post array like this. $data = Yii::$app->request->post(); $reg_res = $data['ColoringForm']['region']; $this->redirect(array('controller/action', 'reg_res'=>$reg_res); You can access this parameter in your action through params
Yes , it is but using other approach like session
thank you very much... i use session approach and it's work :)
0

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

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

2 Comments

is that possible to send data without redirect to another page? i mean just send the data
The above will do that. No redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.