我是 PHP 和 Symfony 3 的初学者,我遇到了一个问题:json_encode 返回空对象。您可以检查下面的图像和代码。
/**
* @Rest\Get("/user")
*/
public function getAction()
{
$restresult = $this->getDoctrine()->getRepository('AppBundle:User')->findAll();
if ($restresult === null) {
return new View("there are no users exist", Response::HTTP_NOT_FOUND);
}
return new Response(json_encode($restresult), Response::HTTP_OK);
}
Run Code Online (Sandbox Code Playgroud)