From 9cda5069925dedf2ded90390bc4f0ae4719878fa Mon Sep 17 00:00:00 2001 From: Dennis Fridrich Date: Sun, 10 Apr 2016 21:38:43 +0200 Subject: [PATCH 1/2] Added docs for JSON helper --- book/controller.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/book/controller.rst b/book/controller.rst index c768b33407d..9995f20e2f2 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -778,6 +778,20 @@ There are also special classes to make certain kinds of responses easier: :class:`Symfony\\Component\\HttpFoundation\\StreamedResponse`. See :ref:`streaming-response`. +JSON helper +~~~~~~~~~~~ + +You can simplify sending JSON response with +:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::json` +helper:: + + public function jsonAction() + { + $data = [1, 2, 3]; + + return $this->json($data); + } + .. seealso:: Now that you know the basics you can continue your research on Symfony From 5ffa35c412552f32703f4e76906d4547778bc16e Mon Sep 17 00:00:00 2001 From: Dennis Fridrich Date: Sun, 10 Apr 2016 22:07:58 +0200 Subject: [PATCH 2/2] Update docs for JSON helper --- book/controller.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/book/controller.rst b/book/controller.rst index 9995f20e2f2..ba2c1421033 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -785,6 +785,10 @@ You can simplify sending JSON response with :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::json` helper:: + $this->json($data, $status = 200, $headers = array(), $context = array()); + +For example if you want to send some simple array you can use it like this:: + public function jsonAction() { $data = [1, 2, 3];