Controller
setVerificationChain()
Signature
Section titled “Signature”setVerificationChain() — returns void
Available in: controller
Category: Configuration Functions
Description
Section titled “Description”Allows you to define the entire verification chain for a controller in a low-level, structured way. Verification chains are used to validate requests, ensuring they meet specific requirements (like HTTP method, parameters, or types) before the controller action executes. Instead of defining individual verifies() calls in each action, you can use setVerificationChain() to set all verifications at once.
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 verifies function. This should represent the entire verification chain that you want to use for this controller. |
Examples
Section titled “Examples”1. Basic verification chain
component extends="Controller" {
function init() {
// Set verification rules for multiple actions
setVerificationChain([
{only="handleForm", post=true},
{only="edit", get=true, params="userId", paramsTypes="integer"}
]);
}
function handleForm() {
// Action logic here
}
function edit() {
// Action logic here
}
}
2. Adding custom error handling
component extends="Controller" {
function init() {
setVerificationChain([
{only="edit", get=true, params="userId", paramsTypes="integer", handler="index", error="Invalid userId"},
{only="delete", post=true, params="id", paramsTypes="integer", error="Missing or invalid id"}
]);
}
function edit() {
/* edit logic */
}
function delete() {
/* delete logic */
}
}