0

I call a controller from my view:

/**
 * Flush new chat message.
 *
 * @Route("/commande/returnMsg", name="new_chat_msg_print", options={"expose"=true})
 */
public function ajaxReturnListAction(Request $request)
{
    $repository = $this->getDoctrine()
                       ->getManager()
                       ->getRepository('MyAwesomeBundle:Chat');

    $listeMsg = $repository->findAll();

    return new Response(json_encode($listeMsg), 200);
}

In the "Chat" Entity, I have 4 fields. But the controller return an empty json result...

[{},{},{},{},{},{},{}]

I don't know how to get the data and return them into json...

Thanks for help !

Macbernie
  • 1,303
  • 6
  • 24
  • 48
  • Just a side note but your can use `return new JsonResponse::create($liteMsg);` as a shortcut to create that type of response. – qooplmao Aug 24 '14 at 18:59
  • http://stackoverflow.com/questions/6706485/how-to-encode-doctrine-entities-to-json-in-symfony-2-0-ajax-application – sebbo Aug 25 '14 at 15:20

0 Answers0