Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda