From 485e95419a40ed0296ae79505c3f5e31ff7fd5a1 Mon Sep 17 00:00:00 2001 From: inoas Date: Thu, 2 Mar 2017 11:46:50 +0100 Subject: [PATCH 1/3] Add _jsonOptions example --- en/views/json-and-xml-views.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/en/views/json-and-xml-views.rst b/en/views/json-and-xml-views.rst index 5d67aa5818..54cf450195 100644 --- a/en/views/json-and-xml-views.rst +++ b/en/views/json-and-xml-views.rst @@ -164,6 +164,13 @@ customize the bit-mask used to generate JSON. See the `json_encode `_ documentation for the valid values of this option. +For example, to gain consistent validation errors from CakePHP to JSON Example:: + + // In your controller's action when saving failed + $this->set('errors', $articles->errors()); + $this->set('_jsonOptions', JSON_FORCE_OBJECT); + $this->set('_serialize', ['errors']); + JSONP Responses --------------- From a6acd0887b6f438010a279bd8663bbaf74553eb8 Mon Sep 17 00:00:00 2001 From: inoas Date: Thu, 2 Mar 2017 14:11:22 +0100 Subject: [PATCH 2/3] wording --- en/views/json-and-xml-views.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/views/json-and-xml-views.rst b/en/views/json-and-xml-views.rst index 54cf450195..2f35124084 100644 --- a/en/views/json-and-xml-views.rst +++ b/en/views/json-and-xml-views.rst @@ -164,7 +164,7 @@ customize the bit-mask used to generate JSON. See the `json_encode `_ documentation for the valid values of this option. -For example, to gain consistent validation errors from CakePHP to JSON Example:: +For example, to gain consistent validation error output of CakePHP entities in form of JSON do:: // In your controller's action when saving failed $this->set('errors', $articles->errors()); From 7bddd63832874ad5c9559e47d4cc401395985a07 Mon Sep 17 00:00:00 2001 From: inoas Date: Thu, 2 Mar 2017 14:12:49 +0100 Subject: [PATCH 3/3] wording --- en/views/json-and-xml-views.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/views/json-and-xml-views.rst b/en/views/json-and-xml-views.rst index 2f35124084..65fe88e8d9 100644 --- a/en/views/json-and-xml-views.rst +++ b/en/views/json-and-xml-views.rst @@ -164,7 +164,7 @@ customize the bit-mask used to generate JSON. See the `json_encode `_ documentation for the valid values of this option. -For example, to gain consistent validation error output of CakePHP entities in form of JSON do:: +For example, to serialize validation error output of CakePHP entities in a consistent form of JSON do:: // In your controller's action when saving failed $this->set('errors', $articles->errors());