From d51e146b7edb5cdf7777f527618656d59a923b66 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 30 Nov 2016 16:35:01 +0100 Subject: [PATCH 1/3] Added docs for JsonResponse::fromJsonString --- components/http_foundation.rst | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/components/http_foundation.rst b/components/http_foundation.rst index 03f054412e4..a2b4ff97a76 100644 --- a/components/http_foundation.rst +++ b/components/http_foundation.rst @@ -547,13 +547,19 @@ class, which can make this even easier:: use Symfony\Component\HttpFoundation\JsonResponse; + // if you know the data to send when creating the response + $response = new JsonResponse(array('data' => 123)); + + // if you don't know the data to send when creating the response $response = new JsonResponse(); - $response->setData(array( - 'data' => 123 - )); + // ... + $response->setData(array('data' => 123)); + + // if the data to send is already encoded in JSON + $response = JsonResponse::fromJsonString('{ "data": 123 }'); -This encodes your array of data to JSON and sets the ``Content-Type`` header -to ``application/json``. +The ``JsonResponse`` class sets the ``Content-Type`` header to +``application/json`` and encodes your data to JSON when needed. .. caution:: From 5f806491583a326b914059f946ad2d4fc3d6f2e6 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 9 Dec 2016 17:15:07 +0100 Subject: [PATCH 2/3] Added a missing "versionadded" directive --- components/http_foundation.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/http_foundation.rst b/components/http_foundation.rst index a2b4ff97a76..d4b096dba5f 100644 --- a/components/http_foundation.rst +++ b/components/http_foundation.rst @@ -558,6 +558,9 @@ class, which can make this even easier:: // if the data to send is already encoded in JSON $response = JsonResponse::fromJsonString('{ "data": 123 }'); +.. versionadded:: 3.2 + The ``JsonResponse::fromJsonString()`` method was added in Symfony 3.3. + The ``JsonResponse`` class sets the ``Content-Type`` header to ``application/json`` and encodes your data to JSON when needed. From fbfe3ed737cee119338d7ca6e051e3cef788e755 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 10 Dec 2016 12:04:18 +0100 Subject: [PATCH 3/3] Fixed the versionadded number --- components/http_foundation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/http_foundation.rst b/components/http_foundation.rst index d4b096dba5f..225726ab550 100644 --- a/components/http_foundation.rst +++ b/components/http_foundation.rst @@ -559,7 +559,7 @@ class, which can make this even easier:: $response = JsonResponse::fromJsonString('{ "data": 123 }'); .. versionadded:: 3.2 - The ``JsonResponse::fromJsonString()`` method was added in Symfony 3.3. + The ``JsonResponse::fromJsonString()`` method was added in Symfony 3.2. The ``JsonResponse`` class sets the ``Content-Type`` header to ``application/json`` and encodes your data to JSON when needed. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy