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

425
Visualizações
How to implement an asynchronous request in EasyAdmin (Symfony)

I need a button that will generate a report in the background, for this I need to use ajax. I implemented a button template and a method to be called on this button, the button is visible in all rows, but it is called only on the first row and many at once (by clicking on the first row, the method is called as many times as there are rows). And it is necessary that it was called for each person separately. Those. by clicking on line 5, the button should fire and pass user_id = 5. Can you please tell me how to add a button to each row correctly and pass data to the controller?

easy_admin:
    entities:
        User:
            class: App\Entities\User
            label: User list
            list:
                fields:
                    - id
                    - { property: name, type: text }
                    - { property: generate, type: button, template: 'generate_report.html.twig' }  // Here I need to somehow convey user_id

Template

{% block generate_report %}
    <input type="button" value="Go" id="generate">

    <script>
        $(function () {
            $('#generate').on('click', function (e) {
                let userId = ? // user_id should be here

                $.ajax({
                    url: "{{ path('generate.report') }}",
                    type: "POST",
                    data: {
                        userId: userId
                    },
                    success: function () {
                        console.log("success")
                    },
                    error: function () {
                        console.log("error")
                    }
                });
            });
        });
    </script>

{% endblock %}

Controller

/**
* @Route(methods={"POST"}, name="generate.report")
*/
public function generateReport(): Response
{
    return $this->json(["success"]);
}
about 4 years ago · Juan Pablo Isaza
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