我与Symfony2合作,我想创建一个注册表。
我不想使用FOSUserBundle。
因此,我创建了一个实体帐户(具有字段:用户名,密码,电子邮件...),并创建了表单:
$account = new Account();
$form = $this->createFormBuilder($account)
->add('username', 'text', array('label' => 'Nom de compte :'))
->add('password', 'password', array('label' => 'Mot de passe :'))
->add('email', 'email', array('label' => 'Adresse email :'))
->getForm();
现在,我想为密码添加一个确认字段。
但是,当我尝试使用add()方法添加字段时,例如“password_confirmation”
我有这个 :
Neither property "password_confirmation" nor method "getPasswordConfirmation()" nor method "isPasswordConfirmation()" exists in class "App\FrontBundle\Entity\Account"
如何添加自定义字段?之后,如何验证呢?
谢谢。
BR。
最佳答案
在正常情况下,您需要使用property_path选项明确指定* password_confirmation *不属于实体。
->add('password_confirmation', 'password', array('property_path' => false))
然后使用CallBackValidator对其进行验证。
但是,在这种特定情况下,如果您想重复一个字段,repeated小部件可以为您完成此操作。
->add('password_confirmation', 'repeated', array(
// See the docs :)
));
关于symfony - Symfony 2:添加自定义表单元素,而不是在实体中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10950203/