Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!