1 回答
TA贡献1818条经验 获得超11个赞
很明显,$post是空的,所以在这种情况下,你可以转储这两个变量,我希望你能弄清楚发生了什么
dump($id);
dump($post);
exit
你可以看文档Doctrine Removing entity
更新:
在您的代码中,您总是在发送响应,您需要将响应更新为特定的成功或错误代码,默认情况下它发送 200 代码,并且您还需要更新您的代码
public function deletePost($id, LoggerInterface $logger)
{
$post=$this->getDoctrine()->getRepository(Article::class)->find($id);
if(!$post)
{
$this->addFlash(
'notice',
'Something went wrong'
);
$logger->info($id);
exit() your code here
or throw an exception here
}
try {
//remove entity here
$response = new Response(
'Content',
Response::HTTP_OK,
['content-type' => 'text/html']
);
return $response;
} catch (\Exception $exception) {
$response = new Response(
$exception->getMessage(),
Response::HTTP_INTERNAL_SERVER_ERROR,
['content-type' => 'text/html']
);
return $response;
}
}
添加回答
举报