@larissa
To add validation rules to a CakePHP model, follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class User extends AppModel { public $validate = array( 'name' => array( 'rule' => 'notEmpty', 'message' => 'Please enter your name' ), 'email' => array( 'rule' => 'email', 'message' => 'Please enter a valid email address' ), 'password' => array( 'rule' => array('minLength', 6), 'message' => 'Your password must be at least 6 characters long' ) ); } |
In this example, we've specified that the name
field must not be empty, the email
field must be a valid email address, and the password
field must be at least 6 characters long.
That's it! You can add additional validation rules as needed by adding additional key-value pairs to the validate
array.