top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can I Add my own Validation Methods in CakePHP?

0 votes
42 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...