Back

setFilterChain()

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.
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.
Copied!