I have two tables Project and User and a join table ProjectUser. I am creating a query to select the users under a certain projectName I couldn't do that so I created a query to select the id of the project according to its name from the project table
public function findName($projectName){
$query=$this->getEntityManager()
->createQuery("SELECT p.id FROM SocialProProjectBundle:Project p WHERE ``p.name='$projectName'");
return $query->getResult();
}
and then a query to select the users through the project id
public function findProjectUsers($pId){
$query=$this->getEntityManager()
->createQuery(
"SELECT pu, u FROM SocialProProjectBundle:ProjectUser pu JOIN SocialProDefaultBundle: User u WHERE pu.project = '$pId'"
);
return $query->getResult();
}
but I always get Notice: Array to string conversion !!!!!
Here is how I called them in the controller
$projectName = $request->get('projectName');
echo($projectName);
$projectId=$this->getDoctrine()->getRepository('SocialProMeetingBundle:meetingUser')->findName($projectName);
echo(count($projectId));
foreach($projectId as $pId) {
$pus = $this->getDoctrine()->getRepository('SocialProMeetingBundle:meetingUser')->findProjectUsers($pId);
}
$response = "<select class=\"select2_multiple form-control\" multiple=\"multiple\">";
foreach ($pus as $user) {//($i=0;$i<count($pus);$i++)
$name[]=array($user->getFirstName());
}
$response = $response . "<option>$name</option>";
$response = $response."</select> ";
return new Response($response);
//return($pus);
//call repository function
}
$nameis an array and you try to display it:<option>$name</option>.$pIdis a object or array not string.