当渲染 $members 数组并以 html 格式输出此代码时,该数组变为 0123456,而不是我在存储库中请求的值。控制器:public function getMembers(UserRepository $userRepository){ $members = $userRepository->getAllMembers(); $entitiyManager=$this->getDoctrine()->getManager(); return $this->render('leaderboard/leaderboard_Rankings.html.twig',['members' => $members]); }存储库:public function getAllMembers(): array { $entityManager = $this->getEntityManager(); $query = $entityManager->createQuery( 'SELECT m.mem_name, m.mem_surname, m.mem_id FROM App\Entity\Member m ORDER BY m.mem_name ASC' ); // returns an array of Product objects return $query->getResult(); } /** * @return User[] Returns an array of User objects */HTML:<table><tr><td> {% for key, item in members %} {{ key }}{% endfor %} </td> <td> {{members.mem_name}} //Does not work </td> </tr></table>错误是:Key "mem_name" for array with keys "0, 1, 2, 3, 4, 5, 6" does not exist.或者该值打印 0123456
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报
0/150
提交
取消