0

ユーザーを管理するための管理領域をコーディングしたいと考えています。

このために、テーブル内のすべてのユーザーをレンダリングしたい indexAction のために、AdminBundle (indexAction、newAction、editAction、deleteAction) に追加の 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

twig テンプレート ファイルで、次のようにします。

<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 に答える