doukeng1922 2014-12-19 14:01
浏览 45
已采纳

PUT请求Body在Slim上为NULL

I think I have read every answer out there regarding problems getting PUT request body on Slim framework (running on Windows XAMPP). None of the solution seem to work for me, so maybe there is another caveat I'm missing.

My php code follows:

require 'Slim/Slim.php';

\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->run();

$app->put('/calendar/update/:id', function($id) use ($app){
    $ev = json_decode($app->request()->getBody());
    echo var_dump($ev);  // NULL
}

I have been testing it in REST tester in PHPStorm, both using parameters and query string - to no avail. I tried to set contentType: application/x-www-form-urlencoded explicitly in my ajax call as well.

Seem to be getting lost here...

  • 写回答

2条回答 默认 最新

  • drpmazn9021 2016-01-05 11:55
    关注

    Had similar issue. If you are using a form to send put request. Add this hidden field to your form. Also don't forget to move $app-run(); to the last line.

    <input type="hidden" name="_METHOD" value="PUT"/>
    

    http://docs.slimframework.com/routing/put/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部