从看跌期权请求Yii2获取数据

时间:2019-03-14 05:40:35

标签: php rest yii2 httprequest

我可以休息API。使用PUT请求更新数据

http://train-basic/stations/21?name=tt

https://i.stack.imgur.com/ZsZsQ.jpg

尝试获取数据:

$request = Yii::$app->request;
$request = $request->post();

$name = $request["name"];
dump($name);

结果,我得到空值。如何解决?

2 个答案:

答案 0 :(得分:0)

从PUT下载数据,如POST

$request = Yii::$app->request;
$id = $request->get('id');
$name = $request->get('name');
$days = $request->get('days');

答案 1 :(得分:0)

要获取通过PUTPATCH请求在请求正文中发送的数据,您应该使用getBodyParam()getBodyParams()

$request = Yii::$app->request;

// returns all parameters
$params = $request->getBodyParams();

// returns the parameter "id"
$param = $request->getBodyParam('id');
     

https://www.yiiframework.com/doc/guide/2.0/en/runtime-requests#request-parameters