Try adding this to your restriction:
/** * @Annotation * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) */
EDIT
This morning I took the time to try to implement a new installation of symfony 3.
Also, if you added @AcmeAssert\Code to a property similar to the following:
use AppBundle\Validator\Constraints as AcmeAssert; // ... /** * @var string * @AcmeAssert\Code * @ORM\Column(name="code", type="string") */ private $code;
Only the field will be checked, so $value represents the value of the property field.
For example, if you assign @AcmeAssert\Code in the $code property in your entity when the form is submitted, the $value your validator will represent the value of the field of your $code property).
If you add @AcmeAssert\Code on top of your entity, as shown below:
use AppBundle\Validator\Constraints as AcmeAssert; class Foo
Then the $ value will represent your complete object, and you can do all the necessary checks using getters.
I added my test project to the repository, you can use it to see how to use two alternatives: sf3-constraint-test
In my example, the AppBundle::Bar object has a restriction on the property, and AppBundle::Foo has a restriction on the whole entity.
Hope you need it!
EDIT2
If you are in a Yamal mapping, use the following to apply a constraint to the entire entity and access the full object in $value in your constraint:
AppBundle\Entity\AcmeEntity: constraints: - App\Bundle\MyBundle\Validator\Constraints\Code: ~
At the top of your display.
And if you just want to apply the restriction to one property and access the field value using $value , stay as you do and execute your logic on $value , which is a string (the value of the field corresponding to the property of the object limited by the display) this is something like:
AppBundle\Entity\AcmeEntity: properties: