爲什麼你會檢查密碼是否是唯一的?這使得完全沒有意義
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())); –
我可以做到這一點。我將修改驗證器唯一原則 –