Hey guys got an issue with Cakephp validation..
I want to know why is partytwo validation going straight to false?
Here is my Relationship model:
<?php
class Relationship extends AppModel{
var $name='Relationship';
public $useTable = 'relationships_users';
public $primaryKey = 'id';
var $validate = array(
'date' => array(
'rule' => array('datevalidation', 'systemDate'),
'message' => 'Current Date and System Date is mismatched'
),
'partytwo'=>array(
'partytwoExists'=>array(
'rule'=> 'userExists',
'message'=>'That username doesnt exist.'
)
)
);
function datevalidation( $field=array(), $compare_field=null ) {
if ($field['date'] > $compare_field)
return TRUE;
else
return FALSE;
}
function userExists($check) {
$userExists= $this->find('count', array('conditions'=>$check));
if($userExists == 1) {
return TRUE;
}else{
return FALSE;
}
}
...
According to the CakePHP book Adding Your Own Validation Methods section, a custom rule that wrote like this
means Cake will runs your
datevalidationmethod like this:With the same fashion,
causes Cake to run
(Simulated calls. Actual calling is using
dispatchMethodat line 3155 of Model.php)So you are most probably need to rewrite your
datevalidationmethod. Furthermore, your code$userExistscan return you a number larger or equal to 0. Your logic is wrong if it returns 2 or more. ConsiderModel::hasAnyinstead. It could be the reason why it is always validated asfalsefor your case.