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().

NameTypeRequiredDefaultDescription
formatsstringnoFormats 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. Restrict an action to HTML only
function show() {
    // This action will only respond with HTML
    onlyProvides("html");
}

2. Restrict an action to JSON and XML
function data() {
    // Only allow JSON or XML responses
    onlyProvides("json,xml");
}

3. Override global provides setting
component extends="Controller" {

    function config() {
        // Globally allow HTML and JSON
        provides("html,json");
    }

    function exportCsv() {
        // Override global, allow only CSV for this action
        onlyProvides("csv");

        orders = model("order").findAll();
    }
}