I was following custom model validators of this page, https://docs.phalcon.io/en/latest/reference/models.html#validating-data-integrity
to build a validators for changing username, if a username exists but not match to current session user, it would return as invalidate.
but I am getting an error of
UniqueValidatorUser::validate() must be compatible with Phalcon\\Mvc\\Model\\ValidatorInterface::validate(Phalcon\\Mvc\\ModelInterface $record)
It was fine with phalcon 1.3.4, but not working with latest 2.0.3
use Phalcon\Mvc\Model\ValidatorInterface;
use Multiple\Models\Users;
class UniqueValidatorUser extends Validator implements ValidatorInterface
{
public function validate($model)
{
$field = $this->getOption('field');
$value = $model->$field;
$di = DI::getDefault();
$condition = 'status = ?0 AND '.$field.' = ?1';
$identity = $di->get('auth')->getIdentity();
if($identity){
$condition .= ' AND id !='.$identity['id'];
}
$users = Users::find([
$condition,
'bind'=>[0=>1, 1=>$value],
]); //** only apply to status=1 user,
if(count($users))
{
$this->appendMessage("User name exist!", $field, "Unique");
return FALSE;
}
return TRUE;
}
}