Hi All, I upgrade to Phalcon 3.0.1 and I have problems with my custom validator. I will show the code below. I know for the changes in the model for validation and I had changed but maybe there is errors. Please tell me how to fix this. Thank you :)
Custom Validation:
use Phalcon\Mvc\Model\Validator;
use Phalcon\Mvc\Model\ValidatorInterface;
use Phalcon\Mvc\EntityInterface;
class ExpenseValidator extends Validator implements ValidatorInterface
{
public function validate(EntityInterface $model)
{
$params = $this->getOption('params');
$message = $this->getOption('message');
if (!$message) {
$message = 'Duplicate';
}
$count = $model::count(
array("conditions" => "carID=" . (int)$params['carID'] . " AND rnameHash='" . $params['rnameHash'] . "' AND rID != '" . $params['rID'] . "' AND rcost=" . (float)$params['rcost'] . " AND dateAdd=" . (int)$params['dateAdd']
)
);
//Tools::viewarray($params);exit;
//echo $count;exit;
if ($count) {
$this->appendMessage($message, '', 'ExpenseValidator');
// Tools::viewarray($this);exit;
return false;
}
return true;
}
}
In model: (It maybe wrong):
/**
* @return bool
*/
public function validation()
{
$validator = new Validation();
$validator->add(new ExpenseValidator(
array(
'params' => array('rID' => $this->rID, 'carID' => $this->carID, 'rnameHash' => $this->rnameHash, 'rcost' => $this->rcost, 'dateAdd' => $this->dateAdd),
'message' => 'Duplicate - ' . $this->rname
)
)
);
return $this->validate($validator);
}