从管理员 Class SonataAdminBundle 获取存储库
get repository from Admin Class SonataAdminBundle
我使用 symfony 2.8 和 SonataAdminBundle,我想查看 'client' 的用户,这是我的代码:
ClientAdmin
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();
}
但是不管用还是没有结果
您可以使用 createQuery 方法自定义列表查询:
<?php
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->andWhere(
$query->expr()->eq($query->getRootAliases()[0] . '.my_field', ':my_param')
);
$query->setParameter('my_param', 'my_value');
return $query;
}
我使用 symfony 2.8 和 SonataAdminBundle,我想查看 'client' 的用户,这是我的代码:
ClientAdmin
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();
}
但是不管用还是没有结果
您可以使用 createQuery 方法自定义列表查询:
<?php
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->andWhere(
$query->expr()->eq($query->getRootAliases()[0] . '.my_field', ':my_param')
);
$query->setParameter('my_param', 'my_value');
return $query;
}