Guest User

Untitled

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