Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony JsonResponse忽略定义的HTTP代码,仅响应200_Php_Nginx_Silex - Fatal编程技术网

Php Symfony JsonResponse忽略定义的HTTP代码,仅响应200

Php Symfony JsonResponse忽略定义的HTTP代码,仅响应200,php,nginx,silex,Php,Nginx,Silex,我正在尝试更改HTTP代码作为响应,但我总是收到200。 下面的代码在两个测试中多次恢复: $app->put('/hdc/v1/pagamento/{pagamento_id}', function($pagamento_id, Request $request) use ($app) { $pagamento = Pagamento::find($pagamento_id); return new JsonResponse(["message"=>"error

我正在尝试更改HTTP代码作为响应,但我总是收到200。 下面的代码在两个测试中多次恢复:

$app->put('/hdc/v1/pagamento/{pagamento_id}', function($pagamento_id, Request $request) use ($app) {

    $pagamento = Pagamento::find($pagamento_id);

    return new JsonResponse(["message"=>"error"],400); // returns 200
}




$app->put('/hdc/v1/pagamento/{pagamento_id}', function($pagamento_id, Request $request) use ($app) {

//    $pagamento = Pagamento::find($pagamento_id);

    return new JsonResponse(["message"=>"error"],400); // returns 400
}
与模型交互时,JsonResponse会受到影响。为什么?


我认为你没有使用好的方法。见:

别扭

我的实体文件帕加门托有

?>
在文件底部。
调用Pagamento::find方法时,它正在发送200个代码头。

我尝试了这个解决方案,它成功了。你有Silex的覆盖错误?没有错误,Thomas。事实上,响应有200个代码。但我希望设置400作为回应。我的问题是,您是否在中间件之后或中间件之前添加了一些?靶心,@Thomaz!为了简化API,我使用了@before:`if(0==strpos($request->headers->get('Content-Type'),'application/json'){$form=json\u decode($request->getContent(),true);$request->request->replace(is_array($form);}@Thomaz,坏消息。。。这个问题一直困扰着我。。。问题编辑。
?>