This is my controller
public function index2Action($name) { $em = $this->getDoctrine()->getEntityManager(); $test = $em->getRepository('RestWebServiceBundle:Test')->findall(); return new Response(json_encode(array('locations' => $test))); }
When I go to the URL I get:
{"locations":[{}]}
However when I use:
public function index2Action($name) { $name ="Adam"; return new Response(json_encode(array('locations' => $name))); }
I get the JSON.
What am I doing wrong? I am trying to get JSON in the first scenario.
UPDATE: I have verified that the $test variable is indeed not empty and when I do a print_r on it, it shows me the following:
Array( [0] => Rest\WebServiceBundle\Entity\Test Object ( [id:protected] => 1 [title:protected] => test title [author:protected] => test author [blog:protected] => this is the blog [tags:protected] => [comments:protected] => [created:protected] => DateTime Object ( [date] => 2012-05-13 00:00:00 [timezone_type] => 3 [timezone] => America/Chicago ) [updated:protected] => DateTime Object ( [date] => 2012-05-13 00:00:00 [timezone_type] => 3 [timezone] => America/Chicago ) ))null