我正在使用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 %}
傻我 这个:
$userManager = $container->get('fos_user.user_manager');
应该:
$userManager = $this->get('fos_user.user_manager');
您仍将希望为您的应用程序打开错误报告。这应该已经抛出了“未知变量”错误消息,并且很难找到。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句