How to add validation rules in reusable validator

Docs said making reusable validator like this. But how exactly are rules added ?
Do i make a new Validator object?

// In src/Model/Validation/ContactValidator.php
namespace App\Model\Validation;

use Cake\Validation\Validator;

class ContactValidator extends Validator
{
    public function __construct()
    {
        parent::__construct();
        // Add validation rules here.
    }
}
1 Like

i wonder too, because i can’t build.

Can you provide more detail? I’m not seeing anywhere in the 3.x or 4.x documentation instructions to write a class that extends Validator.

  • What version of Cake are you using?
  • Link the documentation section your are following
  • Provide more detail about what you’ve tried, and how it fails