I'm trying to show the list of my users. I'm using FOSUser. This is my Controller in which I want to find the list of users in the fos_user table and show it in my affiche page:
<?php
namespace User\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use User\UserBundle\Entity\User;
use Symfony\Component\HttpFoundation\RedirectResponse;
use User\UserBundle\Form\UserType;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
class DefaultController extends BaseController
{
public function indexAction()
{
$response = parent::registerAction();
// ... do custom stuff
return $response;
}
public function getDoctrine()
{
return $this->container->get('doctrine');
}
public function afficheAction()
{
$em = $this->getDoctrine();
$admins = $em->getRepository('UserUserBundle:User')->findAll();
return $this->render('UserUserBundle:Default:affiche.html.twig', array('admins'=>$admins));
}
}
But I get this error
Call to undefined method User\UserBundle\Controller\DefaultController::render() in C:\wamp\www\pfe2\src\User\UserBundle\Controller\DefaultController.php
How could I resolve it?
You probably use FOSUserBundle 1.3.x whose controller classes do not extend the base Controller
class from the FrameworkBundle. Thus, you cannot use the shortcut methods provided by that class, but you have to render the template manually like it is done in the base RegistrationController
class:
public function afficheAction()
{
$em = $this->getDoctrine();
$admins = $em->getRepository('UserUserBundle:User')->findAll();
return $this->container->get('templating')->renderResponse('UserUserBundle:Default:affiche.html.twig', array('admins'=>$admins));
}