Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class AppModel extends Model{
  2.  
  3. function validates($validationVar = 'validate') {
  4.  
  5. // copy the data over
  6. if ($validationVar != 'validate') {
  7. $temp = $this->validate;
  8. $this->validate = $this->{$validationVar};
  9. }
  10. $errors = $this->invalidFields();
  11.  
  12. // copy it back
  13. if ($validationVar != 'validate') {
  14. $this->validate = $temp;
  15. }
  16. if (is_array($errors)) {
  17. return count($errors) === 0;
  18. }
  19. return $errors;
  20. }
  21. }
  22.  
  23. // assuming this was in my model:
  24. var $justTesting = array(
  25. 'name' => array('rule'=>array('minLength', '1'), 'required'=>true, 'message'=> 'CRRRRAAAZZZY!'),
  26. );
  27.  
  28. // I could test against that rule from my controller using:
  29. $this->ModelName->validates('justTesting');
  30. pr($this->ModelName->validationErrors);
Add Comment
Please, Sign In to add comment