Constructor
public __construct ( array $options = [] ) | ||
$options | array | list of parameters to setup the response. Possible values are: - body: the response text that should be sent to the client - statusCodes: additional allowable response codes - status: the HTTP status code to respond with - type: a complete mime-type string or an extension mapped in this class - charset: the charset for the response body |
/** * Constructor * * @param string $code One of Types::CODE_*, or an array containing 'code' and 'data' keys * @param array $data data to return */ public function __construct($code, array $data = array()) { if (is_array($code)) { $body = \Cake\Utility\Hash::merge(array('code' => 'success', 'data' => array()), $code); } else { $body = array('code' => $code, 'data' => $data); } $options = array('type' => 'json', 'body' => json_encode($body)); parent::__construct($options); }