Symfony2 FOSRestBundle:要为HTTP_NO_CONTENT等代码包含哪个类

时间:2014-03-10 10:23:30

标签: symfony fosrestbundle

我想抛出一个HTTP_NO_CONTENT,但是symfony告诉我ClassNotFoundException: Attempted to load class "Codes" from namespace "FOS\Rest\Util". Do you need to "use" it from another namespace?

我实际上在班上做了use FOS\RestBundle\Util\Codes;

我的电话看起来像这样

public function deleteAction($id)
{
  $em = $this->getDoctrine()->getManager();
  $player = $em->getRepository('xxx')->find($id);

  $em->remove($player);
  $em->flush();

  return $this->view(null, new HTTP_NO_CONTENT);
}

为什么找不到那个班级?

1 个答案:

答案 0 :(得分:2)

new HTTP_NO_CONTENT在这里没有感觉!你必须使用FOS\RestBundle\Util\Codes类,

use FOS\RestBundle\Util\Codes;

并指向正确的状态代码,如下所示,

Codes::HTTP_NO_CONTENT // As HTTP_NO_CONTENT is defined as a constant