Symfony:错误一般而不是关闭有关输入(fos用户名)

时间:2015-07-29 10:28:21

标签: forms symfony

早上好, 我已经扩展了我的FOS包并创建了一个用于订阅的表单,一切运行良好,因为有关userName的错误没有链接到字段,它们位于表单的顶部。 我只使用简单的注释,如* @Assert \ NotBlank()。 它完美的电子邮件whitch链接正确错误,但不是$ username。 谢谢你的帮助。

   namespace ***\UserFosBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use ***\UserFosBundle\Form\Type\InfosPersonFormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder

           ->add('userName', 'text', array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
           // ->add('firstName', 'text', array('label' => 'form.firstName', 'translation_domain' => 'FOSUserBundle'))
            ->add('email', 'email', array('translation_domain' => 'FOSUserBundle'))

            ->add('plainPassword', 'repeated', array(
                'type' => 'password',
                'options' => array('translation_domain' => 'FOSUserBundle'),
                'first_options' => array('label' => 'form.password'),
                'second_options' => array('label' => 'form.password_confirmation'),
                'invalid_message' => 'fos_user.password.mismatch',
            ))

        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'OSF\UserFosBundle\Entity\User',
            'validation_groups' => array('Default', 'Registration')
        ));
    }

    // BC for SF < 2.7
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $this->configureOptions($resolver);
    }

    public function getName()
    {
        return 'fos_user_registration';
    }
}

和实体

<?php

namespace ***\UserFosBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * User
 * @ORM\Entity
 * @ORM\Table(name="users")
 * @UniqueEntity("username")
 * @UniqueEntity("email")
 */
class User extends BaseUser
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    protected $facebookId;

    /**
     * le login pour la connexion
     * @var string
     * 
     * @Assert\Length(min = "2", max = "255", minMessage = "form.error.atLeast", maxMessage = "form.error.noMore")  
     */
    protected $username;


    /**
     * @var string
     * @Assert\NotNull()
     * @Assert\Email(message = "form.error.email", checkMX = true)
     */
    protected $email;

    /**
     * Plain password. Used for model validation. Must not be persisted.
     *
     * @var string
     * @Assert\NotNull()
     * @Assert\Regex(pattern="/[A-Z]/", message="form.error.maj")
     * @Assert\Regex(pattern="/[0-9]/", message="form.error.number")
     * @Assert\Length(min = "7", max = "255", minMessage = "form.error.atLeastOnenumber", maxMessage = "form.error.noMore")  
     */
    protected $plainPassword;

    /**
     * @ORM\OneToMany(targetEntity="OSFAPI\Bundle\NotificationBundle\Entity\Notification", mappedBy="user")
     */
    protected $notifications;

    /**
     * @ORM\OneToMany(targetEntity="OSFAPI\Bundle\NotificationBundle\Entity\Device", mappedBy="user")
     */
    protected $devices;

    /**
     * [$person description]
     * @var [type]
     * @ORM\OneToOne(targetEntity="OSF\PersonBundle\Entity\Person", mappedBy="userfos")
     */
    protected $person;
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->notification = new \Doctrine\Common\Collections\ArrayCollection();
        $this->devices = new \Doctrine\Common\Collections\ArrayCollection();
        $this->mobilenotifications = new \Doctrine\Common\Collections\ArrayCollection();

    }

1 个答案:

答案 0 :(得分:0)

riska是对的我只需要小写N&#39;