Back
renderWith()
Instructs the controller to render the data passed in to the format that is requested.
If the format requested is json
or xml
, CFWheels will transform the data into that format automatically.
For other formats (or to override the automatic formatting), you can also create a view template in this format: nameofaction.xml.cfm
, nameofaction.json.cfm
, nameofaction.pdf.cfm
, etc.
// This will provide the formats defined in the `config()` function.
products = model("product").findAll();
renderWith(products);
// Provide a 403 status code for a json response (for example)
msg={
"status" : "Error",
"message": "Not Authenticated"
}
renderWith(data=msg, status=403)
Copied!