2014-09-04 42 views
1

當我嘗試註冊一個新的用戶,該用戶應該是電子郵件唯一的唯一身份時,UniqueEntity約束運行正常,但錯誤位於密碼字段而不是電子郵件字段,任何人知道爲什麼?FOSUserBundle中的密碼字段上的UniqueEntity驗證錯誤

用戶類別:

use FOS\UserBundle\Model\User as FOSUser; 
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; 
(...) 
use Gedmo\Mapping\Annotation as Gedmo; 

/** 
* User 
* 
* @ORM\Table() 
* @UniqueEntity("email") 
* (...) 
*/ 
class User extends FOSUser 

形式:

public function buildForm(FormBuilderInterface $builder, array $options) { 
    $builder 
      ->add('email', 'email', array('label' => 'form.email')) 
      ->add('firstName', null, array('label' => 'form.first_name')) 
      ->add('lastName', null, array('label' => 'form.last_name')) 
      ->add('plainPassword', 'repeated', array(
       'type' => 'password', 
       'first_options' => array('label' => 'form.password'), 
       'second_options' => array('label' => 'form.password_confirmation'), 
       'invalid_message' => 'fos_user.password.mismatch' 
      )) 
    ; 
} 

形式呈現:

{{ form_widget(form) }} 

和錯誤,從探查:

**Origin:** first (the password field) 

Object(Symfony\Component\Form\Form).data.plainPassword.data.second = [email protected] 

不僅密碼字段看起來像是傳遞了整個用戶對象,而是導致了對UniqueEntity約束的驗證,我無法「調試」原因。

回答

1

如果您正在運行symfony 2.5.0 - 2.5.2那麼這是一個與新的驗證API相關的錯誤。這是fixed2.5.3

如果升級,是不是你可以解決它迫使老驗證API在config.yml

validation: 
    enable_annotations: true 
    api: 2.4 # default is auto which sets API 2.5 BC 
+0

嗯,這修正了語境的東西,但現在,因爲我使用的選項電子郵件用戶提供商,我的表單上有一個全局錯誤「用戶名已被使用」,並在我的電子郵件/用戶名字段中出現雙重錯誤「電子郵件已被使用此值已被使用。」 Thx for the answer – 2014-09-08 08:38:18