简体   繁体   中英

Symfony2 Sonata Admin Error

I recently did a vendors/install and now my sonata admin is broken with the following error:

Item "roles" for "" does not exist in SonataAdminBundle::standard_layout.html.twig at line 92

Here is the twig code:

{% if app.security %}
  {% for role in app.security.token.roles %}
    {% if not allowed %}
      {% set allowed = role.role == 'ROLE_SONATA_ADMIN' %}
    {% endif %}
  {% endfor %}
{% endif %}

Anyone have any thoughts?

Thanks!

I searched through admin bundle with blame option and it comes from a commit 7 days ago

So what you have to do is go to deps.lock

Find the adminBundle commit hash(In my case it started with 4a....) replace the hash with 25b401e6271ee0fd896d700d0328b06994e4e138 which is commit before the commit that cause problem

I tried it and dashboard works correctly

Good luck

EDIT

Be careful not to use php bin/vendor update since it will update the commit hash

Use php bin/vendor install

Here is the fix : https://github.com/Wiakowe/SonataAdminBundle/commit/e139527c05b22176ee3efab987ebe752668d4489

Remove lines 90-99 and replace with the following:

{% if app.security and is_granted('ROLE_SONATA_ADMIN') %}

I had the same problem with the last version of SonataAdminBundle. This problem appears if you allow for everybody opening your admin panel. This is not usuall solution at least for the working site.

To grant access to your admin panel for everybody do the following. Place the path /admin under firewall, add into the file security.yml in the section security.firewals the rows

    admin_area:
        pattern: ^/admin
        anonymous: ~

Thus each client will be authorized as anonymous user with existing token and the errors will not appear.

PS Sorry for grammar mistakes, but I think everybody will understand me :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM