为什么你会检查密码是否是唯一的?这使得完全没有意义
UPD:用于创建自己的验证创建/lib/valdator/sfValidatorDoctrineFoobar.class.php
<?php
class sfValidatorDoctrineFoobar extends sfValidatorBase
{
protected function configure($options = array(), $messages = array())
{
$this->addMessage('invalid_record', 'Unable to find the related record');
}
protected function doClean($value){
$status = $this->getCodeStatus($value);
if ($status == 1){
throw new sfValidatorError($this, 'Code is invalid', array('value' => 'invalid code'));
}
if ($status == 2){
throw new sfValidatorError($this, 'Code allready used', array('value' => 'used'));
}
return $value;
}
protected function getCodeStatus($value){
$q = Doctrine_Query::create()->from('Code c');
$q->select('c.hash, c.used');
$q->addWhere('c.hash = ?', $value);
$result = $q->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
if (!$result) return 1;
if ($result['used'] == 1) return 2;
return false;
}
}
只是向你展示一个例子..你就必须改变代码根据您的需要;)
我需要这个。我必须使这也为用户的唯一代码。 –
然后再添加一些熵:-)像$ this-> setCode(sha1($ this-> getPassword()。$ this-> getId()。$ this-> getUsername()。time())); –
我可以做到这一点。我将修改验证器唯一原则 –