background preloader

Cake PHP

Facebook Twitter

Tâches courantes avec CakePHP :: Le Manuel :: Collection 1.2. CakePHP: the rapid development php framework. Pages. Tâches courantes avec CakePHP :: Le Manuel :: Collection 1.2. Tâches courantes avec CakePHP :: Le Manuel :: Collection 1.2. Validation with CakePHP 1.2. Up to now the validation support consisted of four constants (VALID_NOT_EMPTY, VALID_NUMBER, VALID_EMAIL, and VALID_YEAR), everything else you had to do yourself. The new validation class in CakePHP 1.2 is a bit more powerful ;-) The aforementioned constants still work in 1.2, but they are deprecated, so for new code you shouldn’t use them. The usage of the new validation rules follows the following pattern (in your model): var $validate = array('field' => array('rule' => array('validationmethod', 'param1', 'param2'))); Ok, let’s have a look at the validation methods. alphaNumeric should be self-explanatory, it allows only letters and strings.

Var $validate = array('username' => array('rule' => array('alphaNumeric'))); between is a bit misleading, as I expected that it checks whether a number is in a certain range. Var $validate = array('username' => array('rule' => array('between', 3, 10))); blank validates that a field is blank or contains only whitespace characters like tabs or spaces.