Steinbock
Steinbock

Reputation: 868

Symfony2 Constraints\email not found

I installed a email validator for a newsletter form in Symfony2. Locally everything works fine, but if I upload the whole folder to my webhosting i get the following error message:

Fatal error: Class 'Symfony\Component\Validator\Constraints\email' not found in /home/donacico/public_html/spendu/donaci14/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php on line 64

My validation yml looks like this:

# src/Dbe/DonaciBundle/Resources/config/validation.yml
Dbe\DonaciBundle\Entity\Newsletter:
    properties:
        email:
            - email:
                message: The email "{{ value }}" is not a valid email.
                checkMX: true

Dbe\DonaciBundle\Entity\Contact:
    properties:
        email:
            - email:
                message: The email "{{ value }}" is not a valid email.
                checkMX: true

And here is the action of the create controller:

/**
     * Creates a new Newsletter entity.
     *
     */
    public function createAction(Request $request) {
        $entity = new Newsletter();
        $form = $this -> createCreateForm($entity);
        $form -> handleRequest($request);

        if ($form -> isValid()) {
            $em = $this -> getDoctrine() -> getManager();
            $em -> persist($entity);
            $em -> flush();

            $this -> get('session') -> getFlashBag() -> add('newsletterSubscribed', 'Thank you for subscribing!');

        }

        return $this -> render('DbeDonaciBundle:UnderConstruction:index.html.twig', array('entity' => $entity, 'form' => $form -> createView(), ));
    }

Also in the config.yml file I have validation enabled:

framework:
    validation:      { enable_annotations: true }

Any idea what could cause this error?

Upvotes: 0

Views: 701

Answers (2)

Steinbock
Steinbock

Reputation: 868

It really was a error case of case sensitive, but I corrected the wrong one.

src/DbeDonaciBundle/Resources/config/validation.yml

Dbe\DonaciBundle\Entity\Newsletter:
    properties:
        email:
            -  Email :
                message: The email "{{ value }}" is not a valid email.
                checkMX: true

Upvotes: 0

René Höhle
René Höhle

Reputation: 27295

If you work on a linux system its case sensitive.

'Symfony\Component\Validator\Constraints\email'

to

'Symfony\Component\Validator\Constraints\Email'

otherwise the autoloader can't find the file and the class.

Upvotes: 3

Related Questions