Skip to content

Controller

setVerificationChain()

setVerificationChain() — returns void

Available in: controller Category: Configuration Functions

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.

NameTypeRequiredDefaultDescription
chainarrayyesAn 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.
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 */ 
    }
}