Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7161041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:29:56+00:00 2026-05-28T13:29:56+00:00

I have a RegistrationFormType with following validation constraints: public function getDefaultOptions(array $options) { $collectionConstraint

  • 0

I have a RegistrationFormType with following validation constraints:

public function getDefaultOptions(array $options)
    {
        $collectionConstraint = new Collection(array(
            'email' => array(
                new NotBlank(),
                new Email(array('message' => 'Ungültige E-Mail Adresse')),
                ),
            'username' => new Unique(),
            'code' => new MaxLength(array('limit'=>20)),
            'plainPassword' => new MaxLength(array('limit'=>20)),
        ));

        return array(
            'csrf_protection' => false,
            'validation_constraint' => $collectionConstraint,
        );
    }

In order to assure uniqueness I created a Unique Class (extending Contraint) and a UniqueValidator (extending ConstraintValidator) like described here: http://www.michelsalib.com/2011/04/create-your-own-constraint-validator-in-symfony2-a-doctrine-unique-validator/

The problem is, I get following error on submitting the form:

Catchable Fatal Error: Argument 1 passed to ...\Validation\Constraint\UniqueValidator::__construct() must be an instance of Doctrine\ORM\EntityManager, none given

It seems that the EntityManager is not injected into the ConstraintValidator, I created a service definition in my config.yml though:

services:
    eventiply.validator.unique:
        class: Ajado\EventHubBundle\Validation\UniqueValidator
        arguments: 
            entityManager: "@doctrine.orm.entity_manager"
        tags:
            - { name: validator.constraint_validator, alias: validator.unique }

Any ideas how I could progress here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:29:57+00:00Added an answer on May 28, 2026 at 1:29 pm

    Found the problem:

    I had following code in my Unique Constraint:

    /**
     * @Annotation
     */
    class Unique extends Constraint{
        public $message = 'Dieser Wert muss eindeutig sein, ist leider aber schon vergeben';
        public $propertyName;
        public $property;
        public $entityName;
    
        public function __construct($options = null) {
    
            parent::__construct($options);
        }
    
        public function validatedBy()
        { 
            // copied that from http://symfony.com/doc/current/cookbook/validation/custom_constraint.html
            return get_class($this).'Validator';
        }
    }
    

    And this is the corrected one:

    /**
     * @Annotation
     */
    class Unique extends Constraint{
        public $message = 'Dieser Wert muss eindeutig sein, ist leider aber schon vergeben';
    
        public function __construct($options = null) {
    
            parent::__construct($options);
        }
    
        public function validatedBy()
        {
            return 'validator.unique';
        }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have an an array String classname[]={'a','b','c','d'}; ArrayAdapter<CharSequence> adapterClasses = new ArrayAdapter<CharSequence>( getApplicationContext(), R.layout.spinner_item_class, R.id.spinnerclasstxt,
Have some code: using (var ctx = new testDataContext()) { var options = new
Have you managed to get Aptana Studio debugging to work? I tried following this,
have an array of values [1,2,4] representing the values of a multi-select box, how
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
**Have it working now. I forgot to populate the Array List. How embarrassing. I'm
Have converted devise new session from erb to Haml but doens't work, this is
Have been following Rails Tutorial by Michael Hart rails version 3.0 on mac OS
have the following text file: <div> <asp:HyperLinkField HeaderText=Hello World of Regular Expression /> </div>
Have the following scenario. I have a few form, which essentially have a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.