Cakephp extends custom verification rules & nbsp; in CAKEPHP, there are up to 26 verification rules can be used, see here for details: http://book.cakephp.org/view/1181/Adding-your-own-Validation-Methods! /View/1152/Core-Validati cakephp extends custom verification rules
In CAKEPHP, up to 26 verification rules can be used. for details, see here:
Http://book.cakephp.org/view/1181/Adding-your-own-Validation-Methods! /View/1152/Core-Validation-Rules
But how to extend the customization? For example, in an example, only the administrator user needs to check and enter the user name.
(An extreme example), you can do this:
Class User extends AppModel {
Var $ name = 'user ';
Var $ validate = array (
'Name' => array ('notempty '=>
Array ('rule' => array ('notempty '),
'Message' => 'Please enter first name ',
......
.......
'Username' => array ('custom' =>
Array ('rule' => array ('validatedependentfields '),
'Message' => 'Please enter height ',
Here, we use a custom method for username to define a method validateDependentFields for verification.
Method:
function validateDependentFields($field){ $passed=true; switch(true){ case array_key_exists('username',$field): if( $this->data['User']['user_type_id']==1 and (!isset($this->data['User']['username']) or empty($this->data['User']['username'])) ){ $passed=false; }else{ $passed=true; } break; case array_key_exists('class_of',$field): if( $this->data['User']['user_type_id']==1 and (!isset($this->data['User']['class_of']) or empty($this->data['User']['class_of'])) ){ $passed=false; }else{ $passed=true; } break; } return $passed; }
If user_type_id = 1 is the administrator, true is returned, indicating that verification rules are used. otherwise, false is returned.