[英]How to pass data from one controller action to another via POST
I wish to send a POST request from an action of a controller to an action of another controller.我希望将一个 POST 请求从一个控制器的一个动作发送到另一个控制器的一个动作。 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.在目标控制器操作中,我正在访问 POST 数据作为
Yii::$app->request->post()
我希望根据我的需要从另一个控制器修改这个变量。
Please note that I do not want to use $_GET or it's Yii equivalent.请注意,我不想使用 $_GET 或它的 Yii 等价物。
就像我在评论中写的那样,这不是我喜欢的方法,但有一个功能:
Yii::$app->runAction('yourController/yourAction', [$yourParameters]);
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. confirm
是可选的。 Remove it if you don't want to confirm the user action. 如果您不想确认用户操作,请将其删除。
Use following way使用以下方式
Yii::$app->request->setBodyParams(['message' => $message,
'toUserID' => $userID,
'fromUserID'=>$this->userDetails->userid]);
Yii::$app->runAction('/chat/send-message');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.