1
votes

I have a Symfony FOSUserBundle which I am using with my Symfony2 application. I have run into a problem which I need help finding a solution to as I am not sure why it is showing up. After installation, I have tested the registration and login and they work but now when I try the resetting password, it gives me an error "The options "value" do not exist in constraint Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity". I have not modified the symfony2 vendor classes and I am sure I have not added anything else to FOSUserBundle to alter its behaviour. Here is my FOSUserBundle configuration:

fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Main\BundleName\Entity\User
service:
    mailer: fos_user.mailer.twig_swift
registration:
    confirmation:
        enabled: true
        from_email:
            address: ....some email address here
            sender_name:    The senders name

Here is my Entity Class, I have truncated the setters and getters to reduce the length of this post: namespace Main\BundleName\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * User
 *
 * @ORM\Table(name="User")
 * @ORM\Entity
 * @UniqueEntity("email", message="A user with the specified email already exists")
 * @UniqueEntity("username", message="A user with the specified username already exists")
 */
class User extends BaseUser
{


 /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(name="password", type="string", length=255, nullable=false)
     */
    protected $password;

    /**
     * @var string
     */
    protected $salt;

    /**
     * @var string
     *
     * @ORM\Column(name="email", type="string", length=255, nullable=false)

     */
    private $firstName;

    /**
     * @var string
     *
     * @ORM\Column(name="last_name", type="string", length=200, nullable=true)
     */
    private $lastName;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=200, nullable=true)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="thumbnail", type="string", length=200, nullable=true)
     */

     // Getters and Setters ...truncated ....
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set username
     *
     * @param string $username
     * @return User
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Get username
     *
     * @return string 
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return User
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }
}

Any ideas on how to fix this error?

2
can you show us the Factory\WebServicesBundle\Entity\User class ? - Benjamin Lazarecki
Yes, I have added it to the initial post - Paul A.

2 Answers

1
votes

I think the problem is on the uniqueEntity declaration

You should use @UniqueEntity(fields = "email", message="A message") instead of @UniqueEntity("email", message="A message").

When you pass more than one parameters to the UniqueEntity annotation you should declare each parameters. You can use @UniqueEntity("email") only if there is one parameters.

Hope it's helpful.

Best regard.

1
votes

I faced a similar error when clearing the cache after i downgraded from Symfony 2.4 to 2.3.

[Symfony\Component\Validator\Exception\InvalidOptionsException]
The options "value" do not exist in constraint Symfony\Component\Validator\Constraints\Regex

@Benjamin Lazarecki answer helped me finding the solution

When i was in Symfony2.4 this annotation wasn't a problem:

 @Assert\Regex("/^[0-9]{4}(?:-[0-9]{3})?$/", match=true, message="Format XXXX-XXX")

but after the downgrade it seems i need to be explicit when declaring the pattern like the annotation below:

 @Assert\Regex(pattern="/^[0-9]{4}(?:-[0-9]{3})?$/", match=true, message="Format XXXX-XXX")