@@ -73,7 +73,8 @@ When you pass your data in any of these methods, they will determine the data ty
7373the following criteria:
7474
7575* If $data is a string, it will be treated as HTML to send back to the client.
76- * If $data is an array, it will try to negotiate the content type with what the client asked for, defaulting to JSON
76+ * If $data is an array, it will be formatted according to the controller's ``$this->format `` value. If that is empty
77+ it will try to negotiate the content type with what the client asked for, defaulting to JSON
7778 if nothing else has been specified within Config\A PI.php, the ``$supportedResponseFormats `` property.
7879
7980To define the formatter that is used, edit **Config/Format.php **. The ``$supportedResponseFormats `` contains a list of
@@ -104,6 +105,17 @@ JSON data will be sent back to the client.
104105
105106Class Reference
106107***************
108+ .. php :method :: setResponseFormat($format)
109+
110+ :param string $format The type of response to return, either ``json `` or ``xml ``
111+
112+ This defines the format to be used when formatting arrays in responses. If you provide a ``null `` value for
113+ ``$format ``, it will be automatically determined through content negotiation.
114+
115+ ::
116+
117+ return $this->setResponseFormat('json')->respond(['error' => false]);
118+
107119
108120.. php :method :: respond($data[, $statusCode=200[, $message='']])
109121
@@ -186,13 +198,13 @@ Class Reference
186198 :param string $message: A custom "reason" message to return.
187199 :returns: The value of the Response object's send() method.
188200
189- Sets the appropriate status code to use when a command was successfully executed by the server but there is no
201+ Sets the appropriate status code to use when a command was successfully executed by the server but there is no
190202 meaningful reply to send back to the client, typically 204.
191203
192204 ::
193205
194206 sleep(1);
195- return $this->respondNoContent();
207+ return $this->respondNoContent();
196208
197209.. php :method :: failUnauthorized(string $description = 'Unauthorized'[, string $code=null[, string $message = '']])
198210
0 commit comments