显示使用symfony的用户列表

时间:2016-03-29 09:39:25

标签: symfony fosuserbundle

我正在尝试显示我的用户列表,我正在使用FOSUser。这是我的控制器我希望在fos_user表中找到用户列表并在我的affiche页面中显示它

<?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)); 
    }
}

但是我收到了这个错误

Call to undefined method User\UserBundle\Controller\DefaultController::render() in C:\wamp\www\pfe2\src\User\UserBundle\Controller\DefaultController.php 

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您可能使用FOSUserBundle 1.3.x,其控制器类不会从FrameworkBundle扩展基类Controller类。因此,您不能使用该类提供的快捷方法,但您必须手动呈现模板,就像在基类RegistrationController类中完成一样:

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)); 
}