Skip to content
neoneo edited this page Apr 7, 2012 · 4 revisions

At the beginning of the request handling by CFlow, a Response object is created. This object gathers all content that is generated by the views. Content can have different types. Currently only 'TEXT', 'HTML' and 'JSON' are implemented.

Views have direct access to this object.

The Response object has the following methods:

string getType()

Returns the content type of the response: HTML, JSON or TEXT.

void setType(required string)

Sets the content type of the response: HTML, JSON or TEXT.

void append(required any, string = "")

Appends content to the response. The content must be a string, or be serializable to JSON. With the optional second argument you can specify the key under which the response object stores the content. You can use this key with the write() and clear() methods. This key does not have to be unique.

void clear(string = "")

Deletes content from the response. If no string or an empty string is passed, all content is cleared. Otherwise all content associated with the given key is cleared.

void write(string = "", boolean = true)

Outputs content to the page. If a non-empty key string is passed, only the content associated with that key is written to the page. This is useful for views that assemble the output from other views. The second, boolean, argument specifies whether the content should be cleared after it is written. By default, it is true. If you pass false, subsequent calls to write() may output the same content again.

Depending on the content type, it does the following:

  • TEXT and HTML: simple content (IsSimpleValue()) is concatenated and written to the output. Complex content like structs and arrays is ignored.
  • JSON: simple values are ignored. If there is exactly one complex content element in the response, that element is serialized to JSON. If there are multiple complex elements, it serializes them all in an array.

void appendHeader(required string, required string)

Appends a header with the given name (first argument) and value (second argument). Headers are not output automatically, you have to call writeHeaders().

void writeHeaders()

Writes the response headers. Depending on the content type sets the content header (text/html, text/plain or application/json) and any headers set using appendHeader().

Clone this wiki locally