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

174
Visualizações
Get Id from a value in a controller in Symfony

What I am trying to do is to get an Id from a folder number. Both my Id and my folder number (folder number is unique) are in the same controller.

I get the folder number from a text input and I then need to redirect the user to a page /Id.

My question is how should I handle it ?

Do I need to create a method getIdFromFolderNumber() in my controller and then call this function in my JS function ? Or maybe do I need to do everything in a JS function (I know I need a JS function since I will use an AJAX request to redirect my user and to get the value from the input).

I don't need the code or anything, I just want to know the method I need to use to understand how to do it. I've started working on a very big project and since I am a junior developer I am a bit lost.

Thank you for your help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You don't need any JS to achieve that. It's a simple form and redirection.

Once your form which gives you the number is submitted :

$number = $form->get('number')->getData();

Then you got your criteria for your doctrine request :

$id = $yourEntityRepository->findBy(['number' => $number)])->getId();

Now you have your ID for the redirection :

return $this->redirectToRoute('entity_show', ['id' => $id]);

IS that what you were looking for ?

Note : you don't need to store $number and $id as variables. It was only to make it clear. You can replace them by the actual requests where it's needed.

about 4 years ago · Juan Pablo Isaza Relatório
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