-1

I need help sending query list to Twig without headers. I have already query my data and I am stuck. I had to have this data in JSON structure.

This is name of my root: 'AdminBundle:Note:viewPdf.html.twig' And here is name of query class in propel - it is empty now: MnNoteCommentQuery.

Here is my code:

$noteQuery = MnNoteCommentQuery::create()->find();
$responsed = new JSonResponse($noteQuery);
return $this->render('AdminBundle:Note:viewPdf.html.twig', array('notes' => $responsed));
Pang
  • 9,564
  • 146
  • 81
  • 122
Mac
  • 1
  • 2
  • 1
    `JSonResponse` class is a **Response** class, which means it's designed to be returned form controller and not used in view layer (Twig in this example). Use simple `json_decode`/`json_encode` if you need to work with JSON data. – Jakub Matczak Apr 15 '16 at 06:16

1 Answers1

1

Just use json_encode in twig

return $this->render('AdminBundle:Note:viewPdf.html.twig', array('notes' => $notes));

Twig:

{{ notes | json_encode() }}

You can customize json representation by implementing JsonSerializable interface

Arthur
  • 2,869
  • 14
  • 25
  • It's almost work as i want :D but now i have that kind of data in twig: {"0":{"posx":"190px","posy":"287px"}} and the best solution is have array like this: notes={"posx":"190px","posy":"287px"},{"posx":"190px","posy":"287px"} Can i control this somehow? – Mac Apr 15 '16 at 08:39
  • this number in the begining each row normally display name of the bundle. It is possible to delete it from this array? – Mac Apr 15 '16 at 09:39