I am using Cakephp 2.3. In my model, I have a function to check for duplicates. I want to check the number of duplicates and report it to the user. However, the variable I set in the function seems to be not available to me in the view.
Model:
class Student extends AppModel {
public $validate = array(
'promotion_code' => array(
'rule' => array('limitDuplicates', 2),
'message' => "there are x duplicates" )
);
public function limitDuplicates($check, $limit) {
$existing_promo_count = $this->find('count', array(
'conditions' => $check,
'recursive' => -1
));
$this->set('results', $existing_promo_count);
return $existing_promo_count < $limit;
}
}
In the view
debug("duplicate count is ". $results);
results in
Notice (8): Undefined variable: results
Please advice how to display a variable I set in a function in the model to be available to the error message in the View.
Thanks.