php - How to use parameters -
lets have url:
/people/1/friends
both people , friend objects, 1 person can have many friends
friendcontroller looks this
class friendcontroller extends controller { public function indexaction() { $em = $this->getdoctrine()->getmanager(); $entities = $em->getrepository('epiforumbundle:friend')->findall(); return $this->render('epiforumbundle:friend:index.html.twig', array( 'entities' => $entities, )); } }
this index action works can see returns every friend in database. friends 'people_id' == 1. how can select wanted friends? in other words, how can parameter tells specific person?
update
routes
friend: pattern: / defaults: { _controller: "epiforumbundle:friend:index" }
first, name param in indexaction - symfony simple contoller
second, use findby() method on repository:
public function indexaction($peopleid) { $em = $this->getdoctrine()->getmanager(); $entities = $em->getrepository('epiforumbundle:friend')->findby(array( 'people_id' => $peopleid )); return $this->render('epiforumbundle:friend:index.html.twig', array( 'entities' => $entities, )); }
Comments
Post a Comment