Skip to content

Instantly share code, notes, and snippets.

@gabrielslau
Created March 11, 2012 22:11
Show Gist options
  • Select an option

  • Save gabrielslau/2018388 to your computer and use it in GitHub Desktop.

Select an option

Save gabrielslau/2018388 to your computer and use it in GitHub Desktop.
multiple_validation_sets_cakephp
<?php
/*
** Função para validação personalizada
** @link http://snook.ca/archives/cakephp/multiple_validation_sets_cakephp
*/
function validates($options = array()) {
// copy the data over from a custom var, otherwise
$actionSet = 'validate' . Inflector::camelize(Router::getParam('action'));
if (isset($this->validationSet)) {
$temp = $this->validate;
$param = 'validate' . $this->validationSet;
$this->validate = $this->{$param};
} elseif (isset($this->{$actionSet})) {
$temp = $this->validate;
$param = $actionSet;
$this->validate = $this->{$param};
}
$errors = $this->invalidFields($options);
// copy it back
if (isset($temp)) {
$this->validate = $temp;
unset($this->validationSet);
}
if (is_array($errors)) {
return count($errors) === 0;
}
return $errors;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment