数组呈现为数字而不是值

当渲染 $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


qq_遁去的一_1
浏览 112回答 1
1回答

翻翻过去那场雪

解决方法:&nbsp;{%&nbsp;for&nbsp;key,&nbsp;item&nbsp;in&nbsp;members&nbsp;%}&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;{{item.mem_name}} {%&nbsp;endfor&nbsp;%}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5