Это мой контроллер
public function index2Action($name)
{
$em = $this->getDoctrine()->getEntityManager();
$test = $em->getRepository('RestWebServiceBundle:Test')->findall();
return new Response(json_encode(array('locations' => $test)));
}
Когда я перехожу по URL-адресу, я получаю:
{"locations":[{}]}
Однако, когда я использую:
public function index2Action($name)
{
$name ="Adam";
return new Response(json_encode(array('locations' => $name)));
}
Я получаю JSON.
Что я делаю не так? Я пытаюсь получить JSON в первом сценарии.
ОБНОВЛЕНИЕ: я проверил, что переменная $test действительно не пуста, и когда я выполняю для нее print_r, она показывает мне следующее:
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
Подробнее здесь: https://stackoverflow.com/questions/105 ... -symfony-2