I'm trying to build a dynamic text field with AJAX autocomplete.
I defined a method into the controller which is used for the AJAX call.
public function cityAction(Request $request)
{
$repository = $this->getDoctrine()
->getRepository('UserCityBundle:District');
$items = $repository->findAll();
// $format = $request->getRequestFormat();
// \Doctrine\Common\Util\Debug::dump($items);
return $this->render('CommonAjaxBundle:Default:index.html.twig', array('data' => array(
'success' => true,
'root' => 'district',
'count' => sizeof($items),
'rows' => $items
)));
}
Into the twig file:
{{ data | json_encode | raw }}
I took that from an example of how make an ajax call in Symfony2. It should print a json encode of my District entity repository but i got this result:
{"success":true,"root":"district","count":6,"rows":[{},{},{},{},{},{}]}
Why it doesn't print the fields between the brackets ?