5

安装Symfony2 cmf后,当我尝试查看管理/仪表板时,出现以下错误:

SonataAdminBundle :: standard_layout.html.twig 第 95 行中不存在函数“is_granted”

4

2 回答 2

10

我也为此挣扎了很长时间。以下是解决方法:

将 SecurityBundle 添加到app/AppKernel.php

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

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

security.yml在您的文件夹中创建一个app/config,例如使用此演示内容:

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 }

并将其加载到您的app/config/config.yml

imports:
    - { resource: security.yml }

这对我有用。

于 2013-05-15T15:02:53.157 回答
-2

就像对其他可能面临此问题的人的反馈一样:

acme 的解决方案有效。显然,必须按照中所述提供用户

http://symfony.com/doc/master/cmf/tutorials/creating-cms-using-cmf-and-sonata.html

于 2013-05-16T10:57:16.060 回答