Hi, am I retarded or 2.1 beta cant work with custom validations ?
namespace Phalcon\Plugins\customValidators;
class dbUnique extends \Phalcon\Validation\Validator implements \Phalcon\Validation\ValidatorInterface {
public function __construct(array $options = array()){
$this->db = \Phalcon\DI::getDefault()->getDb();
}
/**
* Executes the validation
*
* @param Phalcon\Validation $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute){
return false;
$value = $validator->getValue($attribute);
echo "<pre>";
print_r($value);
echo "</pre>";
exit;
return true;
}
}
in my model :
public function validation()
{
$validator = new Validation();
$validator->add(
'email',
new EmailValidator()
);
$validator->add(
'email',
new \Phalcon\Plugins\customValidators\dbUnique([
'message' => 'email already exist',
])
);
return !$this->validationHasFailed();
}
no matter what i call $user->validation() or /$user->save(); i never see false as a responce
$user = new \Phalcon\Models\User();
$user->setActive(0);
$user->setEmail($this->request->getPost('email', 'email', ''));
echo "<pre>";
var_dump($user->validation());
var_dump($user->save());
echo "</pre>";
exit;