Hi,
In model i write a validation and custom validation, rule if i going to add a state its want to check with a function checkStates() if the data is present then its validation want to fail, how to do this please help me.
public function validation() {
$this->validate(new PresenceOf(array(
"field" => "State",
'message' => 'The State is required',
'with' => $this->checkStates($this)
)));
return $this->validationHasFailed() != true;
}
function checkStates($data){
$parameters = $this->persistent->parameters;
if (!is_array($parameters)) {
$parameters = array();
}
$countryid=$data->CountryId;
$State=$data->State;
$parameters["conditions"] = 'CountryId = '.$countryid;
$parameters["columns"] = 'id';
$states = States::findFirst($parameters);
if($states->id){
return false;
}else{
return true;
}
}