Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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 检索所有用户restful api symfony2_Php_Json - Fatal编程技术网

Php 检索所有用户restful api symfony2

Php 检索所有用户restful api symfony2,php,json,Php,Json,我试图使用FOSRestBundle、JMSSerializerBundle库检索json格式的用户列表,但遇到了一个问题。 控制器看起来像: namespace System\ApiBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; use FOS\RestBundle\Controller\Annotations\View; use Symfony\Bundle\Framew

我试图使用FOSRestBundle、JMSSerializerBundle库检索json格式的用户列表,但遇到了一个问题。 控制器看起来像:
    namespace System\ApiBundle\Controller;

    use FOS\RestBundle\Controller\FOSRestController;
    use FOS\RestBundle\Controller\Annotations\View;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;

    class UserController extends Controller
    {
        /**
         * @View()
         * @return array
         */
        public function allAction()
        {
            $em = $this->getDoctrine()
               ->getEntityManager();

            $users = $em->getRepository('AppBundle:User')
                        ->findAll();
            return array(
                    'users' => $users,
            );
        }
      ..........
但它返回给我这个错误

{
 "error": 
  {
    "code": 500,
    "message": "Internal Server Error",
    "exception": 
   [

   {
    "message": "Warning: Invalid argument supplied for foreach()",
    "class": "Symfony\\Component\\Debug\\Exception\\ContextErrorException",
    "trace": 
    [

      {
        "namespace": "",
        "short_class": "",
        "class": "",
        "type": "",
        "function": "",
        "file": "/var/www/html/project/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php",
        "line": 101,
        "args": 
        [

        ]
      },
      ..................

但是,如果我用find($id)替换findAll(),则特定用户的json将毫无问题地出现。

能否显示实体用户的代码?能否显示实体用户的代码?