I am using symfony2 and FosUserBundle as a user manager. I want to display all users. I have tried the code below but it returns a blank page.
How can I fix it?
controller :
<?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));
}
}
twig :
<h1>get all users</h1>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
Silly me. This:
$userManager = $container->get('fos_user.user_manager');
Should be:
$userManager = $this->get('fos_user.user_manager');
You will still want to get your error reporting turned on for your application. This should have tossed an "unknown variable" error message and would have been trivial to track down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With