[英]SonataAdmin, add menu on left
I'm working on Symfony2 and SonataAdminBundle. 我正在研究Symfony2和SonataAdminBundle。
I need to know how to add a menu in the left part of my dashboard ? 我需要知道如何在仪表板的左侧添加菜单? Like in the screen :
就像在屏幕上一样:
I need to have the Dashboard block in the left part on the page (in dark-grey on my screen).. how can i do that ? 我需要在页面的左侧部分显示仪表板块(在我的屏幕上以深灰色显示)..我该怎么做?
you can see on the demo of SonataAdmin http://demo.sonata-project.org/admin/dashboard , login admin, apssword admin 您可以在SonataAdmin的演示中看到http://demo.sonata-project.org/admin/dashboard ,登录管理员,apssword管理员
http://blog.eike.se/2014/03/custom-page-controller-in-sonata-admin.html http://blog.eike.se/2014/03/custom-page-controller-in-sonata-admin.html
this post helped me. 这篇文章帮助了我。
extend template 扩展模板
vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig
override block 覆盖块
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block side_bar_after_nav %}
YOUR CUSTOM MENU
{% endblock %}
I've just added ROLE_SONATA_ADMIN to ROLE_ADMIN in security.yml: 我刚刚在security.yml中将ROLE_SONATA_ADMIN添加到ROLE_ADMIN:
security:
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
and it shown up, finaly. 它最终显示出来了。 For more info check this: https://github.com/sonata-project/SonataAdminBundle/issues/2321
有关更多信息,请查看: https : //github.com/sonata-project/SonataAdminBundle/issues/2321
The first thing to do is to open this file in this path: 要做的第一件事是在此路径中打开此文件:
\\wamp\\www\\YourProject\\vendor\\sonata-project\\admin-bundle\\Resources\\view \\standard_layout.html.twig \\ wamp \\ www \\ YourProject \\ vendor \\ sonata-project \\ admin-bundle \\ Resources \\ view \\ standard_layout.html.twig
Then look for : ROLE_SONATA_ADMIN
(using Ctrl+F) then changed to the role that you are using to log in to your admin dashboard for me I'm using ROLE_ADMIN
, then save the file, close it, check your admin dashboard, you will find exactly what you look for. 然后查找:
ROLE_SONATA_ADMIN
(使用Ctrl + F)然后更改为您用来登录管理仪表板的角色我正在使用ROLE_ADMIN
,然后保存文件,关闭它,检查您的管理仪表板,您将找到你想要的东西。
hope it will works 希望它会奏效
well, if you want to use the automatic menu generated by sonata you can use this steps to reach the point: 好吧,如果你想使用奏鸣曲生成的自动菜单,你可以使用这个步骤来达到这一点:
Solution 解
override the default sonata layout twig file from config.yml
覆盖
config.yml
的默认sonata布局config.yml
文件
sonata_admin: templates: layout: ::layout.html.twig
your ::layout.html.twig
: 你的
::layout.html.twig
:
{% extends 'SonataAdminBundle::standard_layout.html.twig' %} {% block side_bar_nav %} {{ knp_menu_render('sonata_admin_sidebar', {template: sonata_admin.adminPool.getTemplate('knp_menu_template')}) }} {% endblock %}
Why this solution? 为什么这个解决方
since the default SonataAdminBundle::standard_layout.html.twig
checks the user to have the ROLE_SONATA_ADMIN
permission (and you might not using sonata user bundle
), you need to override permission checking process, which is by default: 由于默认的
SonataAdminBundle::standard_layout.html.twig
检查用户是否具有ROLE_SONATA_ADMIN
权限(并且您可能不使用sonata user bundle
),因此您需要覆盖权限检查过程,默认情况下:
{% block side_bar_nav %}
{% if app.user and is_granted('ROLE_SONATA_ADMIN') %}
{{ knp_menu_render('sonata_admin_sidebar', {template: sonata_admin.adminPool.getTemplate('knp_menu_template')}) }}
{% endif %}
{% endblock side_bar_nav %}
I think this is the easiest way to use navigation buttons on left sidebar. 我认为这是在左侧边栏上使用导航按钮的最简单方法。
okay finally, 好吧,最后,
it seems they updated sonata admin bundle doc, 看来他们更新了sonata admin bundle doc,
take a look at this => http://sonata-project.org/bundles/admin/master/doc/reference/architecture.html 看看这个=> http://sonata-project.org/bundles/admin/master/doc/reference/architecture.html
or with user bundle : 或者用户捆绑:
http://sonata-project.org/bundles/user/master/doc/reference/user_dashboard.html http://sonata-project.org/bundles/user/master/doc/reference/user_dashboard.html
hope it will works 希望它会奏效
Do two things: 做两件事:
Create a template called standard_layout.html.twig
in your custom bundle's Resources/views
folder. 在自定义捆绑包的
Resources/views
文件夹中创建名为standard_layout.html.twig
的模板。 Add this to that template: 将其添加到该模板:
{% extends 'SonataAdminBundle::standard_layout.html.twig' %} {% block side_bar_nav %} //add your code here {% endblock side_bar_nav %}
PS: Look at block side_bar_nav
in vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig
for direction PS:查看
vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig
中的块side_bar_nav
以获取方向
app/config/config.yml
(or wherever your config file is), add: app/config/config.yml
(或您的配置文件所在的位置),添加: sonata_admin: templates: layout: YourBundle::standard_layout.html.twig
I recommend using YourBundle:Admin:standard_layout.html.twig
to organize all your admin templates into a single Admin
folder. 我建议使用
YourBundle:Admin:standard_layout.html.twig
将所有管理模板组织到一个Admin
文件夹中。 You'd need to change the location of the template in step 1 accordingly 您需要相应地更改步骤1中模板的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.