diff --git a/en/views/json-and-xml-views.rst b/en/views/json-and-xml-views.rst index 5d67aa5818..65fe88e8d9 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 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()); + $this->set('_jsonOptions', JSON_FORCE_OBJECT); + $this->set('_serialize', ['errors']); + JSONP Responses ---------------