[英]Symfony2 - SonataAdmin Bundle
Hi?你好? I'm struggling with SonataAdmin Bundle.
我正在努力使用 SonataAdmin Bundle。 I'm Tryng to do a FAQ system.
我正在尝试做一个常见问题系统。
Here is my actual config.这是我的实际配置。 With an Question an Category entities:
使用问题和类别实体:
services:
sonata.admin.faq_question:
class: FM\AppBundle\Admin\Faq\Question
tags:
- { name: sonata.admin, manager_type: orm, group: "FAQ", label: "Questions" }
arguments:
- ~
- FM\AppBundle\Entity\Faq\Question
- ~
sonata.admin.faq_category:
class: FM\AppBundle\Admin\Faq\Category
tags:
- { name: sonata.admin, manager_type: orm, group: "FAQ", label: "Categories" }
arguments:
- ~
- FM\AppBundle\Entity\Faq\Category
- ~
With this system, I have a two menu (Questions and Categories).有了这个系统,我有两个菜单(问题和类别)。 I would like to have just one menu where I see the Questions grouped by Categories.
我希望只有一个菜单,我可以在其中看到按类别分组的问题。
Do you think it is possible with the default config of Sonata?您认为 Sonata 的默认配置可能吗?
Do I need to override the listAction method in the CRUDController.我是否需要覆盖 CRUDController 中的 listAction 方法?
What you need can be resumed in two main things:你需要的东西可以在两个主要方面恢复:
For the first (hide Categories), change the following in your service declaration:对于第一个(隐藏类别),在您的服务声明中更改以下内容:
sonata.admin.faq_category:
# ...
tags:
- { show_in_dashboard: false, name: sonata.admin, manager_type: orm, group: "FAQ", label: "Categories" }
# ...
For the last, add the following to your QuestionAdmin class:最后,将以下内容添加到您的 QuestionAdmin 类中:
/**
* {@inheritDoc}
*/
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
// Assuming the Question entity has a $categories field+association
$query
->leftJoin($query->getRootAliases()[0].'categories', 'c')
->groupBy('c.id')
return $query;
}
Hope that fits your need.希望这适合您的需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.