I had the same error and it solved it.
As Lewiz correctly stated, you should create a validator using Phalcon\Validation and then pass it to the validate method.
Model's 'validate' method now expects Phalcon\Validation
, which implements Phalcon\ValidationInterface
. And \Phalcon\Validation\Validator\Uniqueness
and other validators which you pass to Model’s ‘validate’ method are implementing Phalcon\Validation\ValidatorInterface
that’s why you see this error after upgrade to newest phalcon, yes it maybe confusing, but everything works as documented.
Given the above, If you upgraded phalcon from deprectaed version fist you need:
1) change Phalcon\Mvc\Model\Validator\....
to \Phalcon\Validation\Validator\
e.g Phalcon\Mvc\Model\Validator\Uniqueness
to \Phalcon\Validation\Validator\Uniqueness
2) change
public function validation()
{
$this->validate(new Uniqueness([
'field' => 'email',
'message' => 'The email is already registered'
]));
return $this->validationHasFailed() != true;
}
to
public function validation()
{
$validation = new Validation();
$validation -> add('email', new Uniqueness([
'field' => 'email',
'message' => 'The email is already registered'
]));
return $this->validate($validation);
}
where Validation is instance of \Phalcon\Validation
class