我使用symfony 2.8和SonataAdminBundle,我想查看“客户端”用户,这是我的代码:
客户管理员
protected function configureListFields(ListMapper $listMapper)
{
$result = $this->getConfigurationPool()->getContainer()->get('Doctrine')->getRepository('UserBundle:User')->findClient();
$listMapper
->add('client', 'sonata_type_model', array(
'empty_value' => '',
'choice_list' => $result))
;
}
用户存储库
public function findClient()
{ $dql = "SELECT p FROM UserBundle:User p WHERE p.type LIKE 'client' ORDER BY p.id DESC";
return $this->getEntityManager()
->createQuery($dql)
->getResult();
}