top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I Add my own Validation Methods in CakePHP?

0 votes
375 views
How can I Add my own Validation Methods in CakePHP?
posted Jul 31, 2014 by Mohit Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

class User extends AppModel {

public $validate = array(
    'promotion_code' => array(
        'rule'    => array('limitDuplicates', 25),
        'message' => 'This code has been used too many times.'
    )
);

public function limitDuplicates($check, $limit) {
    // $check will have value: array('promotion_code' => 'some-value')
    // $limit will have value: 25
    $existingPromoCount = $this->find('count', array(
        'conditions' => $check,
        'recursive' => -1
    ));
    return $existingPromoCount < $limit;
}

}

answer Aug 1, 2014 by Rahul Mahajan
...