Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- class AppModel extends Model{
- function validates($validationVar = 'validate') {
- // copy the data over
- if ($validationVar != 'validate') {
- $temp = $this->validate;
- $this->validate = $this->{$validationVar};
- }
- $errors = $this->invalidFields();
- // copy it back
- if ($validationVar != 'validate') {
- $this->validate = $temp;
- }
- if (is_array($errors)) {
- return count($errors) === 0;
- }
- return $errors;
- }
- }
- // assuming this was in my model:
- var $justTesting = array(
- 'name' => array('rule'=>array('minLength', '1'), 'required'=>true, 'message'=> 'CRRRRAAAZZZY!'),
- );
- // I could test against that rule from my controller using:
- $this->ModelName->validates('justTesting');
- pr($this->ModelName->validationErrors);
- ?>
Add Comment
Please, Sign In to add comment