Symfony 2 Doctrine export to JSON

后端 未结 3 518
一生所求
一生所求 2021-01-18 12:15

I\'m using Symfony 2 with Doctrine 2 to create a web service(JSON) for an iOS app.

To fetch my entity i do:

$articles = $this->getDoctrine()->g         


        
3条回答
  •  我在风中等你
    2021-01-18 12:53

    If you use a doctrine query you can also do this:

      $em = $this->getDoctrine()->getEntityManager();
      $query = $em->createQuery('SELECT ma FROM UdoPaddujourBundle:MenuArticle ma ...etc');
      $myArray = $query->getArrayResult();
    

    and then json_encode($myArray); See here for more details

提交回复
热议问题