configureShowFields中的自定义查询

时间:2013-02-19 18:21:11

标签: symfony doctrine-orm sonata-admin

我的问题很简单,但我没有解决方案。

如何为configureShowFields创建自定义查询?

所以在configureListFields中我们有一个createQuery($context = 'list')函数......在类似的情况下我想在configureShowFields中创建自定义查询。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题:

我找不到这样做的特殊功能,我也在Controller中创建了一个函数showAction:

public function showAction($id = null) {
    $id = $this->get('request')->get($this->admin->getIdParameter());

    $object = $this->admin->getObject($id);
    $em = $this->getDoctrine()->getManager();

    if (!$object) {
        throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
    }

    if (false === $this->admin->isGranted('VIEW', $object)) {
        throw new AccessDeniedException();
    }
    $user = $em->getRepository('EsolvingEschoolUserBundle:User')->findOneByUserIdByLanguage($object->getId(), $this->getRequest()->getLocale());

    $this->admin->setSubject($object);

    return $this->render($this->admin->getTemplate('show'), array(
                'action' => 'show',
                'object' => $user,
                'elements' => $this->admin->getShow(),
    ));
}

所以在我的存储库中我做了我的自定义查询,我发布了解决方案,也许是我帮助的人