Symfony形式和循环与学说[关闭]

I have recently started using Symfony. I write a doctrine query and i found the values I needed but i have the problem when i want to enter values in a form's textbox with a for loop.. This is my query:

 $id_user = $user->getId();
        $query = $em->createQueryBuilder()
     ->select('ur','uu')   
     ->from('DtEcBundle:UserReferences', 'ur')
     ->innerJoin("ur.id_user","uu")
     ->where("ur.id_user = :id_user")
     ->setParameter("id_user",$id_user)
            ->getQuery();
            $userpyramid = $query->getResult();

And now i would insert my values in a form..

 $form = $this->get('form.factory')->createNamedBuilder('form', 'form')
        ->setMethod('POST')
        ->setAction($this->generateUrl('profilo_secondlevel'))
        ->add('idreferenced', 'text', array(
                'data' =>  '',
            ))
        ->add('save', 'submit', ['label' => 'Prova'])
        ->getForm();

If I understood your question correctly, you don't really need any form!
Just pass the ArrayCollection to twig, iterate over it and display all values you need. After that, define a route paramized by id that you can access by a link.

So, basically

//somewhere in controller
/**
 * @Route("/showSomethingByUserId/{uid}") <-- this could be also inserted into .yml file
 */
public function showSomethingByUserIdAction($uid)
{
    //implement some code to check $uid (just an example)
}

Pass $userpyramid to twig

//somewhere in controller
public function extractAllIdUsersAction()
{
    [...]
    //should be better to create a repository for this
    $id_user = $user->getId();
    $query = $em->createQueryBuilder()
        ->select('ur','uu')   
        ->from('DtEcBundle:UserReferences', 'ur')
        ->innerJoin("ur.id_user","uu")
        ->where("ur.id_user = :id_user")
        ->setParameter("id_user",$id_user)
        ->getQuery();
    $userpyramid = $query->getResult();

    return $this->render('YourBundle:Folder:TwigName.html.twig, array(
        'userPyramid' => $userpyramid)
    );
}

Then in your twig

{% for user in userpyramid %}
    {{ user.name }}
    {{ user.surname }}
    <a href="{{ path('showSomethingByUserId', {'uid': user.id}) }}">Access to user infos</a>
{% endfor %}

Of course your names may vary accordingly