im working on a project with symfony3 and im beginner at this framework this is my problem i have a table in data base called groupe wher i have a colum called member in which i have stored the id's of members in this group table database
in the first step i would like to get those ids from the groupe table and then explode them to send queries to my database to get the nom,prenomand the profile pic that correspand to the id send so i have made two action in my repository
this is my first action in my repository which allow me to get string of id from table membre in my database
public function getmemberstring($id){
$membres = $this->getEntityManager()
->createQuery('SELECT g.membres FROM GroupGroupBundle:Groupe g
WHERE g.id =:id')
->setParameter('id',$id);
return $membres->getResult();
}
and this is my seccond function in my repository that allows me to extract id from the previous string and send request to database to get the information that i want
public function getmemberlist($list){
$memberId = explode('-',$list);
$membres = array();
foreach($memberId as $value){
$nom = $this->getEntityManager()
->createQuery('SELECT m.nom FROM MainBundle:Member m
WHERE m.id =:id')
->setParameter('id',$value);
$nom = $nom->getResult();
$prenom = $this->getEntityManager()
->createQuery('SELECT m.prenom FROM MainBundle:Member m
WHERE m.id =:id')
->setParameter('id',$value);
$prenom = $prenom->getResult();
$pic = $this->getEntityManager()
->createQuery('SELECT m.profile_pic FROM MainBundle:Member m
WHERE m.id =:id')
->setParameter('id',$value);
$pic = $pic->getResult();
array_push($membres,$nom,$prenom,$pic);
}
return $membres;
}
this is my controller
public function membreGroupeAction()
{
$em = $this->getDoctrine()->getManager();
$str = $em->getRepository("GroupGroupBundle:Groupe")->findOneBy(array('id'=>1));
$member = $em->getRepository("GroupGroupBundle:Groupe")->getmemberlist($str->getMembres());
return $this->render('@GroupGroup/layout/membres.html.twig',array("mem"=>$member));
}
this is my twig view wher i want to show my send by the controller
{% extends '@GroupGroup/Group/groupe_mur_base.html.twig' %}
{% block panel %}
{% for i in mem %}
{% for j in i %}
{% for t in j %}
{{ t }}
{% endfor %}
{% endfor %}
{% endfor %}
<div class="jumbotron list-content" style="display: block;">
<ul class="list-group">
<li href="#" class="list-group-item title">
Liste des Membres
</li>
<li href="#" class="list-group-item text-left" id="listmembre" style="display: block;">
<div class="image">
<img class="img-thumbnail" src="http://bootdey.com/img/Content/User_for_snippets.png">
<span id="membername">Juan guillermo cuadrado</span>
<div><button id="btnajout" class="btn btn-primary">Ajouter</button></div>
</div>
<div class="break"></div>
</li>
this is how my data appears in my template i want to style them and to get only the 3 item for each user separated in li list like the template belowmy template