Symfony 3 - Get a list from a dropdown

Hi,
I would like to display the list of my client table join with my facture table from a select, but I can not.
Nothing appears, no result while I like that the list corresponding to the selected id is displayed, I am still a beginner in symfony 3, if someone can help me and show me how to do?
thank you in advance,
here is my code
View

{% extends "::base.html.twig" %}

{% block title %}{{ title() }}{% endblock %}

{% block body %}
    <div class="row">
        <div class="container">
            <div class="col-md-6">
                <label>Numeros :</label>
                <select>
                    {% for num in num %}
                        <option name="id">{{ num.numeros }}</option>
                    {% endfor %}
                </select>
            </div>

            <div class="col-md-6" align="right">
                {{ render(controller('AppBundle:List:list')) }}
                {% for list in liste %}
                {{ liste.nom }}
                {{ liste.adresse }}
                {{ liste.code }}
                {% endfor %}
            </div>
        </div>
    </div>
{% endblock %}

Controller

public function avoirNumAction()
    {
        $em    = $this->getDoctrine()->getManager();
        $dql   = "Select c.num from AppBundle:Client c";
        $query = $em->createQuery($dql);
        $num = $query->getResult();

        return $this->render('AppBundle:List:avoirnum.html.twig', array('num' => $num
            // ...
        ));
    }

public function listAction(Request $request)
    {
        $em    = $this->getDoctrine()->getManager();
        $id = $request->request->get('id');
        $dql   = " select c.nom, c.adresse, f.code from AppBundle:Client c inner join AppBundle:Facture f
        with c.id = f.id where c.id = :id ";
        $query = $em->createQuery($dql)
                    ->setParameter('id', $id);
        $list = $query->getResult();

        return $this->render('AppBundle:List:list.html.twig', array('list' => $list,
        ));
    }

Well, to start with:

{% for num in num %}

Shoud be something like

{% for num in nums %}

And of course

$nums = $query->getResult();

Your code is definitely not typical for Symfony so I don’t really know if the above changes will get you a bit further or not.

Your list section will not work as you expect but I’d suggest getting the select working first.

ok thanks for your answer,
the select works already but I do not get the list after selecting on the select is the problem.
I don’t know where wrong???

Are you expecting that your list will be automatically updated after selecting something in your browser? If so then you will need significantly different code.

Yes, I want it automatically, but I don’t know what fo it :frowning:

I honestly don’t know where to even start here as it appears that your knowledge of how web apps in general work is a bit lacking. Consider working your way through the following articles:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.