【发布时间】:2015-04-01 10:56:43
【问题描述】:
我正在尝试使用 Backbone.js 以 REST 方式将集合保存到我的数据库中,并在我的服务器上运行 SLIM php 框架。
这是我的收藏:
var newUser = this.collection.create(
formData,
{
wait: true,
success: $.proxy(function() {
this.collection.currentUser = newUser;
App.Router.navigate('', { trigger: true });
}, this)
}
);
这是我的 SLIM 路线:
$api->post('/users', function() use($api, $db) {
$request = $api->request()->post();
$api->response()->header('Content-Type', 'application/json');
$result = $db->users()->insert($user);
if( $result ) {
echo json_encode(array(
'id' => $result['id']
));
}
else {
echo json_encode(array(
'status' => false,
'message' => 'error_creating_user'
));
}
});
$api->run();
在我的集合上调用 create() 时,我在服务器的响应中收到弃用警告:
Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
我已按照这些说明进行了以下操作:
我在路线之前添加了这个:
ini_set('always_populate_raw_post_data', '-1');
在我的 POST 路由中,我尝试像这样接收请求负载:
$request = file_get_contents('php://input');
对我的代码进行此更改后,我得到的响应保持不变...
编辑
即使回调为空,也会发生错误......
$api->post('/users', function() use($api, $db) {
// nothing
});
【问题讨论】:
标签: php backbone.js xmlhttprequest slim postdata