登録フォームにEWZRecaptchaを追加しようとしています。 私の登録フォームビルダは、次のようになります。Symfony2登録フォームにreCaptchaフィールドを追加
今public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('username', 'text')
->add('password')
->add('recaptcha', 'ewz_recaptcha', array('property_path' => false));
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Acme\MyBundle\Entity\User',
);
}
、私はキャプチャフィールドにreCAPTCHAの制約を追加することができますか?
namespaces:
RecaptchaBundle: EWZ\Bundle\RecaptchaBundle\Validator\Constraints\
Acme\MyBundle\Entity\User:
...
recaptcha:
- "RecaptchaBundle:True": ~
しかし、私は
Property recaptcha does not exists in class Acme\MyBundle\Entity\User
エラーを取得する:私はvalidation.ymlにこれを追加しようとしました。
私はreCAPTCHAのフィールドのオプションからarray('property_path' => false)
を削除すると、私はエラーを取得する:
Neither property "recaptcha" nor method "getRecaptcha()" nor method "isRecaptcha()"
exists in class "Acme\MyBundle\Entity\User"
それを解決するためにどのように任意のアイデア? :)
素晴らしい記事、ありがとうございます! – tamir
symfony 2.1では、 'property_path = false'の代わりに' mapped = false'を使うべきです。http://symfony.com/doc/current/reference/forms/types/form.html#property-pathとhttp: //symfony.com/doc/current/reference/forms/types/form.html#mappedとなります。 –