Skip to content

Controller

provides()

provides() — returns void

Available in: controller Category: Configuration Functions

Defines formats that the controller will respond with upon request. The format can be requested through a URL variable called format, by appending the format name to the end of a URL as an extension (when URL rewriting is enabled), or in the request header.

NameTypeRequiredDefaultDescription
formatsstringno—Formats to instruct the controller to provide. Valid values are html (the default), xml, json, csv, pdf, and xls.
// 1. Allow the controller to respond to HTML and JSON requests
// Place this call inside the controller's config() function
provides("html,json");

// 2. Allow all supported formats for an API controller
provides("html,xml,json,csv,pdf,xls");

// 3. JSON-only controller (e.g. a pure REST API controller)
// Any request for a format other than json will be rejected
provides("json");