Controller
setFilterChain()
Signature
Section titled “Signature”setFilterChain() — returns void
Available in: controller
Category: Configuration Functions
Description
Section titled “Description”Provides a low-level way to define the complete filter chain for a controller. This lets you explicitly specify the sequence of filters, their scope, and the actions they apply to, all in a single configuration. Filters are functions that run before, after, or around actions to handle tasks such as authentication, logging, or IP restrictions.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
chain | array | yes | — | An array of structs, each of which represent an argumentCollection that get passed to the filters function. This should represent the entire filter chain that you want to use for this controller. |
Examples
Section titled “Examples”1. Basic filter chain
// Set filter chain directly
setFilterChain([
{through="restrictAccess"}, // runs for all actions by default
{through="isLoggedIn, checkIPAddress", except="home, login"}, // exclude certain actions
{type="after", through="logConversion", only="thankYou"} // after filter for specific action
]);
//First filter: restrictAccess runs before all actions.
//Second filter: isLoggedIn and checkIPAddress run before all actions except home and login.
//Third filter: logConversion runs after the thankYou action only.
2. Using only and except with different filter types
setFilterChain([
{through="authenticateUser", only="edit, update, delete"}, // only for sensitive actions
{through="trackActivity", except="index, show"}, // for most actions except viewing
{type="after", through="sendAnalytics"} // after all actions
]);
//Demonstrates selective filtering with only and except.
//Can combine before (default) and after filters in the same chain.
3. Multiple filters in one chain struct
setFilterChain([
{through="validateSession, checkPermissions", only="admin, settings"},
{through="logRequest"},
{type="after", through="cleanupTempFiles"}
]);
//Multiple filters can run together (validateSession and checkPermissions).
//Mix of before and after filters ensures proper order and execution context.