Sí con el validador de devolución de llamada: http://symfony.com/doc/current/reference/constraints/Callback.html
En Symfony 2.0:
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContext;
/**
* @Assert\Callback(methods={"isDateValid"})
*/
class Conference
{
// Properties, getter, setter ...
public function isDateValid(ExecutionContext $context)
{
if ($this->startDate->getTimestamp() > $this->endDate->getTimestamp()) {
$propertyPath = $context->getPropertyPath() . '.startDate';
$context->setPropertyPath($propertyPath);
$context->addViolation('The starting date must be anterior than the ending date !', array(), null);
}
}
}
En Symfony versión maestra:
public function isDateValid(ExecutionContext $context)
{
if ($this->startDate->getTimestamp() > $this->endDate->getTimestamp()) {
$context->addViolationAtSubPath('startDate', 'The starting date must be anterior than the ending date !', array(), null);
}
}
Aquí me eligen para mostrar el mensaje de error en el campo startDate .
Marcó la respuesta de @Sykehoe, que debería ser un comentario en lugar de una respuesta, por lo tanto, reformulando su comentario aquí. 'addViolationAtSubPath' está en desuso desde la versión 2.2, use [addViolationAt] (http://api.symfony.com/2.3/Symfony/Component/Validator/ExecutionContextInterface.html#method_addViolationAt) en su lugar. – astorije