php - AllowEmpty vs NotEmpty -
new cakephp here - i'm going through documentation on site, trying muster basic data validation model i'm creating. first of many questions have cakephp.
in cakephp book, validation rules seem specify 2 different methods making sure field isn't empty - allowempty
, , notempty
.
question - there tangible difference between these two? cakephp states validation rules should occur in model or controller - 1 better suited model, , other controller? book doesn't this. i'm guessing 1 older method that's still around?
what gives? should use specific one, or both, or not matter?
edit: decided check cakephp 1.3 class documentation (to check default value of allowempty
attribute), doesn't show up. it's not in source code either...is there i'm missing?
welcome cake. hope enjoy it.
this 1 of stranger aspects of cake.
notempty
rule in , of itself. can define in $validation
attribute. can assign message when validation fails. can treat if other validation rule.
allowempty
option of validation rule, not notempty
. it not validation rule in-and-of-itself. allow, example, define varchar
field allows empty string, '', or string no more 20 characters.
edit:
here's code
// model validation using 'notempty' $validation = array( 'fieldname' => array( 'notempty' => array( 'rule' => 'notempty', 'message' => 'this value may not left empty!' ), ... // other rules can go here ), ... // other fieldname can go here ); // model validation using 'allowempty' create optional field $validation = array( 'fieldname' => array( 'maxlength' => array( 'rule' => array('maxlength', 20), 'message' => 'this field may contain 20 characters!', 'allowempty' => true // we'll accept empty string ), ... // other rules can go here ) ... // other fieldname can go here );
Comments
Post a Comment