Reputation: 655
I wish to send a POST request from an action of a controller to an action of another controller. In the destination controller action , I am accessing POST data as Yii::$app->request->post()
I wish to modify this variable from another controller based on my need.
Please note that I do not want to use $_GET or it's Yii equivalent.
Upvotes: 2
Views: 1949
Reputation: 151
Use following way
Yii::$app->request->setBodyParams(['message' => $message,
'toUserID' => $userID,
'fromUserID'=>$this->userDetails->userid]);
Yii::$app->runAction('/chat/send-message');
Upvotes: 0
Reputation: 3777
Try this:
<?= Html::a('Link Text', ['controller/action'], [
'data'=>[
'method' => 'post',
'confirm' => 'Are you sure you want to submit this?',
'params'=>['id' => 21, 'val2' => true],
]
]) ?>
Adjust your values accordingly. The confirm
is optional. Remove it if you don't want to confirm the user action.
Upvotes: 0
Reputation: 175
Like i wrote it in the comment, this would'nt be my prefered approach, but there is a function for that:
Yii::$app->runAction('yourController/yourAction', [$yourParameters]);
Upvotes: 1