数组到字符串的转换错误Symfony 3 [英] Array to String Conversion Error Symfony 3
问题描述
我有两个表Project和User,还有一个联接表ProjectUser.我正在创建查询以选择某个projectName下的用户,但我无法执行此操作,因此我创建了一个查询以根据项目名称从项目表中选择项目的ID
public function findName($projectName){
$query=$this->getEntityManager()
->createQuery("SELECT p.id FROM SocialProProjectBundle:Project p WHERE ``p.name='$projectName'");
return $query->getResult();
}
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();
}
然后是通过项目ID选择用户的查询
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
}
推荐答案
您好:对于您关于如何解决它的for循环问题,请使用以下代码:
Hi: for the for loop question you had on how to solve it, use this code:
$response = "<select class=\"select2_multiple form-control\" multiple=\"multiple\">";
foreach($pus as $user){
$response . "<option>" . $user->getFirstName() . "</option>";
}
$response = $response."</select> ";
这篇关于数组到字符串的转换错误Symfony 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!