我正在尝试配置约束验证。
使用 Symfony\Component\Validator\Constraint;
我的禁忌:
<?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";
}
}
我的验证器:
<?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);
}
}
我的验证.yml:
Acme\MyBundle\Entity\Broadcasting:
properties:
start_time:
- Acme\MyBundle\Validator\Constraints\OverlapBroadcasting:
message: truc
- NotBlank: ~
我的服务.yml:
acme.validator.overlap_broadcasting:
class: Acme\MyBundle\Validator\Constraints\OverlapBroadcasting
arguments: [@doctrine.orm.entity_manager]
tags:
- {name: validator.constraint_validator, alias: overlap_broadcasting}
但我有这个错误:
No default option is configured for constraint Acme\MyBundle\Validator\Constraints\OverlapBroadcasting