Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The function "is_granted" does not exist in SonataAdminBundle

After installing Symfony2 cmf, when I tried to view the admin / dashboard I have the following error:

The function "is_granted" does not exist in SonataAdminBundle :: standard_layout.html.twig at line 95

like image 378
user896552 Avatar asked Mar 08 '13 17:03

user896552


1 Answers

I struggled with that quite a lot of time, too. Here's how to fix it:

Add the SecurityBundle to app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        // support for the admin
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
    );
    // ...
}

Create a security.yml in your app/config folder, e.g. with this demo content:

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        in_memory:
            memory:
                users:
                    user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                    admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            pattern: ^/
            anonymous: ~
            http_basic:

                realm: "Secured Demo Area"
    access_control:
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
        #- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }

and load it it your app/config/config.yml:

imports:
    - { resource: security.yml }

That worked for me.

like image 91
acme Avatar answered Nov 17 '22 06:11

acme