Created
March 11, 2012 22:11
-
-
Save gabrielslau/2018388 to your computer and use it in GitHub Desktop.
multiple_validation_sets_cakephp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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