I'm using Phalcon framework, and I'm trying to make a custom validator:
<?php
use Phalcon\Validation\Validator,
Phalcon\Validation\ValidatorInterface,
Phalcon\Validation\Message;
class Currency extends Validator implements ValidatorInterface
{
/**
* Executes the validation
*
* @param Phalcon\Validation $validator
* @param string $attribute
* @return boolean
*/
public function validate($validator, $attribute)
{
$value = $validator->getValue($attribute);
if(! is_numeric($value))
{
$message = $this->getOption('message');
if(! $message){
$message = 'Not a valid currency.';
}
$validator->appendMessage(new Message($message, $attribute, 'Currency'));
return false;
}
return true;
}
}
I get this error when trying to use the validator above:
Unexpected value type: expected object implementing Phalcon\Mvc\Model\ValidatorInterface, object of type Currency given
I put the validator class in /plugins/validators/Currency.php and auto-loaded it of course using DI. Any clues?
Phalcon\Validation\ValidatorInterfacewhile the interfacePhalcon\Mvc\Model\ValidatorInterfaceis expected. - Ulrich Thomas Gabor