I'm trying to configure a constraint validation.
use Symfony\Component\Validator\Constraint;
My contraint:
<?php
namespace Acme\MyBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class OverlapBroadcasting extends Constraint
{
public $message = 'overlap date';
public function validatedBy()
{
return "overlap_broadcasting";
}
}
My validator:
<?php
namespace Acme\MyBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class OverlapBroadcastingValidator extends ConstraintValidator
{
private $entityManager;
public function __construct( $entityManager)
{
$this->entityManager = $entityManager;
}
public function validate($value, Constraint $constraint)
{
var_dump($value);
}
}
my validation.yml:
Acme\MyBundle\Entity\Broadcasting:
properties:
start_time:
- Acme\MyBundle\Validator\Constraints\OverlapBroadcasting:
message: truc
- NotBlank: ~
my service.yml:
acme.validator.overlap_broadcasting:
class: Acme\MyBundle\Validator\Constraints\OverlapBroadcasting
arguments: [@doctrine.orm.entity_manager]
tags:
- {name: validator.constraint_validator, alias: overlap_broadcasting}
But I have this errror :
No default option is configured for constraint Acme\MyBundle\Validator\Constraints\OverlapBroadcasting
Having reproduced the error by copying the code into my current project I'm fairly certain the problem is in the services.yml. The class is set to the constraint class when it should be the validator class. The service definition should be:
acme.validator.overlap_broadcasting:
class: Acme\MyBundle\Validator\Constraints\OverlapBroadcastingValidator
arguments: [@doctrine.orm.entity_manager]
tags:
- {name: validator.constraint_validator, alias: overlap_broadcasting}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With