Back
setFilterChain()
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!