0

我想编写一个用于管理用户的管理区域。

为此,我在我的 AdminBundle(indexAction、newAction、editAction、deleteAction)中为 indexAction 创建了一个额外的 UserController,我想在一个表中呈现所有用户。

为了获取所有用户,FOSUserBundle 在 userManager 中提供了一个方法:

    public function indexAction()
{
    $userManager = $this->get('fos_user.user_manager');

    $users = $userManager->findUsers();

    print_r($users);

    return $this->render('KSRAdminBundle:User:index.html.twig', array(
        'users' => $users,
    ));
} 

我现在的问题是我不知道如何渲染如此复杂的数组。

我通过 print_r 查看了数组,不知道该怎么做

最好的问候, 博多凯撒

4

1 回答 1

1

在你的树枝模板文件中做这样的事情。

<table>
    <thead>
        <tr>
            <th>User ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Actions</th>
        </tr>
    </thead>    
    <tbody>
    {% for user in users %}
        <tr>
            <td>{{ user.id }}</td> 
            <td>{{ user.username }}</td> 
            <td>{{ user.email }}</td> 
            <td>
                <a href="#">delete</a>
                <a href="#">edit</a>
            </td> 
        </tr>
    {% endfor %}
    </tbody>
</table>
于 2013-02-28T23:12:55.287 回答