【问题标题】:FOSUserBundle render multidimensional user dataFOSUserBundle 渲染多维用户数据
【发布时间】:2012-04-06 05:28:54
【问题描述】:

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

为此,我在我的 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 查看了数组,不知道该怎么办

最好的问候, 博多凯撒

【问题讨论】:

    标签: php arrays symfony render fosuserbundle


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2021-02-16
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多