2013-10-09 32 views
4

顶部菜单没有出现在我的索纳塔管理员。菜单只出现在仪表板中。Symfony 2 - 顶部菜单没有出现在索纳塔管理员

我也跟着下面的教程,创造了博客功能的后端: http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/tutorial/creating_your_first_admin_class/introduction.html

我也试过配置应用程序/配置/ config.yml类似如下

sonata_admin: 
    dashboard: 
     groups: 
      Blog: 

但预期的结果(即顶部菜单)没有被获得。

回答

1

config.yml文件中导入包yml文件。

例如:

imports: 
    - { resource: @yourBundle/Resources/config/admin.yml } 

admin.yml看起来是这样的:

# website/yourBundle/Resources/config/admin.yml 
services: 
    sonata.admin.your: 
     class: website\yourBundle\Admin\yourAdmin 
     tags: 
      - { name: sonata.admin, manager_type: orm, group: "Content", label: "Contact Management" } 
     arguments: 
      - ~ 
      - website\yourBundle\Entity\your 
      - ~ 
     calls: 
      - [ setTranslationDomain, [yourBundle]] 
+0

我已经在config.yml中给出如下内容: 服务: tutorial.blog.admin.post: class:Tutorial \ BlogBu​​ndle \ Admin \ PostAdmin 标签: - {name:sonata.admin,manager_type :orm,group:Blog,label:Post} arguments:[null,Tutorial \ BlogBu​​ndle \ Entity \ Post,TutorialBlogBu​​ndle:PostAdmin] – Beniston

3

2.2版,它的安全问题。一旦你配置了as the docs says,菜单将正确显示。

UPDATE:此外,根据the 2012-06-05 entry on the changelog,用户必须具有ROLE_SONATA_ADMIN的角色。

如果你想测试它不这样做,你可以根据这个文件set a new layout templatehttps://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/views/standard_layout.html.twig,但评论相关菜单中的块sonata_top_bar_nav画些线条,就像这样:

{% block sonata_top_bar_nav %} 
    {#% if app.security.token and is_granted('ROLE_SONATA_ADMIN') %#} 
    {% for group in admin_pool.dashboardgroups %} 
     {% set display = (group.roles is empty or is_granted('ROLE_SUPER_ADMIN')) %} 
     {% for role in group.roles if not display %} 
      {% set display = is_granted(role) %} 
     {% endfor %} 

     {# Do not display the group label if no item in group is available #} 
     {% set item_count = 0 %} 
     {% if display %} 
      {% for admin in group.items if item_count == 0 %} 
      {% if admin.hasroute('list') and admin.isGranted('LIST') %} 
       {% set item_count = item_count+1 %} 
      {% endif %} 
      {% endfor %} 
     {% endif %} 

     {#% if display and (item_count > 0) %#} 
      <li class="dropdown"> 
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ group.label|trans({}, group.label_catalogue) }} <span class="caret"></span></a> 
      <ul class="dropdown-menu"> 
      {% for admin in group.items %} 
       {#% if admin.hasroute('list') and admin.isGranted('LIST') %#} 
       <li><a href="{{ admin.generateUrl('list')}}">{{ admin.label|trans({}, admin.translationdomain) }}</a></li> 
       {#% endif %#} 
      {% endfor %} 
      </ul> 
      </li> 
     {# % endif %#} 
     {% endfor %} 
    {#% endif %#} 
    {% endblock %} 
2

您需要SONATA_ROLE_ADMIN显示菜单

您可以设置它在security.yml为ROLE_ADMIN包括它

security: 
    ... 
    role_hierarchy: 
     ... 
     ROLE_ADMIN:  [ROLE_USER, ROLE_SONATA_ADMIN] 
     ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 
     ...