Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
Symfony Callback constraints on collectiontype

I want to constraint the value startTime must be lower than endTime.

Below is the inside of collectiontype form.

public function buildForm(FormBuilderInterface $builder, array $options)
{
    \Doctrine\Common\Util\Debug::dump($options);
    $builder
    ->add('startTime',TimeType::class, [
        'required' => false,
        'input' => 'string',
    ])
    ->add('endTime', TimeType::class, [
        'required' => false,
        'input' => 'string',
        'constraints'=>[
             new Assert\Callback(array($this, 'validateInterval')),
        ],
    ])
}



public function validateInterval($value, ExecutionContextInterface $context)
{
    $form = $context->getRoot();
    $data = $form->getData();

    print_r($data);

    if ($data[shoul be some number]['startTime'] >= $value) {
        $context
            ->buildViolation('The end value has to be higher than the start value')
            ->addViolation();
    }
}

$data is this below

Array ( 
    [data] => Array ( 
        [1] => Array ( 
            [id] => 1 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [2] => Array ( 
            [id] => 2 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [3] => Array ( 
            [id] => 3 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00 
        ) 
        [4] => Array ( 
            [id] => 4 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [5] => Array ( 
            [id] => 5 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [6] => Array ( 
            [id] => 6 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [7] => Array ( 
            [id] => 7 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00 
        ) 
    ) 
)

I want to pass the right [id] to the validateInterval constraint.

Is it possible to pass different numbers to each fields?

help me please.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda