简体   繁体   English

如何通过 POST 将数据从一个控制器操作传递到另一个控制器操作

[英]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.

相关问题 将数据从一个控制器动作传递到另一个控制器动作cakephp - pass data from one controller action to another controller action cakephp 如何通过 controller 将帖子数据从一个视图传递到另一个视图 - how can I pass on a post data from one view to another through a controller 通过POST将JSON数据从AngularJS传递到Laravel Controller - Pass JSON data from AngularJS to Laravel Controller via POST 通过$ .post将变量从一个PHP文件传递到另一个 - Pass a variable from one PHP file to another via $.post 如何通过post方法将数据从ajax传递到laravel 5.2控制器 - How to pass data from ajax to laravel 5.2 controller via post method 如何在Symfony 3中将表单变量从控制器操作传递到另一个变量 - How to pass a form variable from a controller action to another in Symfony 3 将数据从一个控制器动作传递到另一个-Magento - Passing data from one controller action to another - Magento 如何在Laravel中将变量从一个控制器传递到另一个控制器 - How to pass variable from one controller to another controller in laravel 如何在Laravel中将值从一个控制器传递给另一个控制器 - How to pass a value from one controller to another controller in laravel 如何在一个使用Laravel的控制器中将数据从一个功能传递到另一个功能? - how to pass data from one function to another, in one controller using Laravel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM