Closed Ali1 closed 11 years ago
Useful when 'Security' component is turned off.
Tweaked to allowEmpty fields, however I'm sure there is a better way to do this which relies on 'notEmpty'=> true ?
public function validateEnum($check,$allowEmpty=false){
$field=key($check);
$value=$check[$field];
if($allowEmpty && empty($value)) return true;
elseif(empty($value)) return false;
$values=$this->enum($field);
if(empty($values)) return false;
if(isset($values[$value])) return true;
else return false;
}
Here we go!
public function validateEnum($check,$rule){
$field=key($check);
$value=$check[$field];
if(!$rule['notEmpty'] && empty($value)){
return true;
}elseif(empty($value)){
return false;
}
$values=$this->enum($field);
if(empty($values)){
return false;
}
if(isset($values[$value])){
return true;
}
return false;
}
So 'rule' => array('validateEnum')
actually triggers the behavior method? Cool.
Don't see no reason against implementing this.
Exactly. I'm using it now and it's working perfectly.
On 16 July 2013 18:54, Miles Johnson notifications@github.com wrote:
So 'rule' => array('validateEnum') actually triggers the behavior method? Cool.
Don't see no reason against implementing this.
— Reply to this email directly or view it on GitHubhttps://github.com/milesj/Utility/issues/11#issuecomment-21060398 .
Added but had to change it slightly.
$this->enum is a pretty good method to get an array of enum key-value pairs but a method to use in $validate may also be handy. See example:
Feel free to use this method which is working well for me.