我使用 symfony2 和 FosUserBundle 作为用户管理器。我想显示所有用户。我已经尝试了下面的代码,但它返回一个空白页。
我该如何解决?
控制器 :
<?php
namespace Annuaire\AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class AdminController extends Controller {
public function indexAction() {
return $this->render('AnnuaireAdminBundle:Admin:index.html.twig');
}
//get all users
public function usersAction() {
//access user manager services
$userManager = $container->get('fos_user.user_manager');
$users = $userManager->findUsers();
return $this->render('AnnuaireAdminBundle:Admin:users.html.twig', array('users' => $users));
}
}
树枝:
<h1>get all users</h1>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}