0

i am trying to build an custom validator with symfony2 but something strange happens:

i have created both Password and PasswordValidate by following the steps in symfony2 cookbook but first time when i load the page i get this error:

AnnotationException: [Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\Password" in property NMSP\MyBundle\Entity\User::$password does not exist, or could not be auto-loaded. 

after reloading the error disappears and the validation still not fires and it return the code is valid.

here is the relevant code:

//annotation declaration:
/**
 * @ORM\Column(type="string", length="32", unique="true")
 * 
 * @Assert\MinLength(3)
 * @Assert\Password2()
 */
protected $password;

//load files with the following in the code
services:
  validator.password:
    class: NMSP\MyBundle\Validator\PasswordValidator
    tags:
        - { name: validator.constraint_validator, alias: password }

can`t figure this one out:(

1 Answer 1

6

Assuming your custom validator constraint is not in the Symfony\Component\Validator\Constraints namespace, but your own namespace: NMSP\MyBundle\Validator.

You should add the following use statement:

use NMSP\MyBundle\Validator as NMSPAssert;

Then use the following annotation on the $username property:

@NMSPAssert\Password()

That should do it.

Sign up to request clarification or add additional context in comments.

2 Comments

still need a little more help. i can not figure out how to access the database within de custom validator and how to get the value of an other entity property like for verifing(password = passconf)...i reread the documentation but they don`t talk about this:(
You probably have figure it out, but here is the answer to your question from the comment above: stackoverflow.com/questions/8934607/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.