Skip to content

Controller

onlyProvides()

onlyProvides() — returns void

Available in: controller Category: Provides Functions

Use this in an individual controller action to define which formats the action will respond with. This can be used to define provides behavior in individual actions or to override a global setting set with provides in the controller’s config(). Restrictions are enforced (since 4.0.4): renderWith() falls back to the html view for a format outside the list, and the automatic render in $callAction() skips view rendering for non-acceptable, non-html formats.

NameTypeRequiredDefaultDescription
formatsstringno—Formats to instruct the controller to provide. Valid values are html (the default), xml, json, csv, pdf, and xls.
actionstringno[runtime expression]Name of action, defaults to current.
// 1. Override a global `provides()` setting for a single action — only respond with HTML
onlyProvides("html");

// 2. Allow a specific action to respond with JSON and XML only
onlyProvides("json,xml");

// 3. Override the provides formats for a named action from within another context (e.g. config())
onlyProvides(formats="json", action="create");