SonataAdminBundle无法在右上角

时间:2016-10-02 21:32:58

标签: symfony

一切正常,但我看不到右上角的注销图标和+图标 我跟着奏鸣曲项目官方网站的所有步骤,但我不知道真正发生了什么。在官方网站上,我在最后一步注销中看到了演示,但在我的项目中我不能 enter image description here 我使用symfony 2.8.0 这是我的config.yml

    imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@AppBundle/Resources/config/admin.yml" }
parameters:
    locale: en

framework:
    #esi:             ~
    translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }
# app/config/config.yml
sonata_block:
    default_contexts: [cms]
    blocks:
        # enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts: [admin]

2 个答案:

答案 0 :(得分:1)

有一种简单的方法可以实现这一点,而无需添加SonataUserBundle。 您可以为 user_block 使用自定义模板,您可以通过执行以下操作添加注销链接和指向某个配置文件视图的链接。

将此添加到 security.yml

security:
  role_hierarchy
    ROLE_ADMIN:      [ROLE_USER, ROLE_SONATA_ADMIN]

现在将此添加到您的 config.yml

## Sonata Configuration
# Sonata Admin
sonata_admin:
  ## ... other config
  templates:
    user_block: AppBundle:Default:user_block.html.twig

最后在 src / AppBundle / Resources / views / Default / 中添加一个名为 user_block.html.twig 的模板文件,其中包含您想要的链接和内容(低于SonataUserBundle默认 user_block 的示例

{#
  This file is part of the Sonata package.
  (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  For the full copyright and license information, please view the LICENSE
  file that was distributed with this source code.
#}

{% block user_block %}
    {% if app.user %}
        {% set _bg_class          = "bg-light-blue" %}
        {% set _logout_uri        = url('sonata_user_admin_security_logout') %}
    {% set _logout_text       = 'user_block_logout'|trans({}, 'SonataUserBundle') %}
    {% set _profile_uri       = sonata_user.userAdmin.isGranted('EDIT', app.user) ? sonata_user.userAdmin.generateUrl('edit', {id: app.user.id}) : sonata_user.userAdmin.generateUrl('show', {id: app.user.id}) %}
    {% set _profile_text      = 'user_block_profile'|trans({}, 'SonataUserBundle') %}
    {% set _user_image        = sonata_user.defaultAvatar ? asset(sonata_user.defaultAvatar) : null %}
    {# Customize this with your profile picture implementation, see below for example #}
    {#{% set _user_image  = app.user.profilePicture|default(asset(sonata_user.defaultAvatar)) %}#}

    {% if is_granted('ROLE_PREVIOUS_ADMIN') and sonata_user.impersonating %}
        {% set _bg_class    = "bg-light-green" %}
        {% set _logout_uri  = url(sonata_user.impersonating.route, sonata_user.impersonating.parameters| merge({'_switch_user': '_exit'})) %}
        {% set _logout_text = 'switch_user_exit'|trans({}, 'SonataUserBundle') %}
    {% endif %}

    <li class="user-header {{ _bg_class }}">
        {% if _user_image %}
            <img src="{{ _user_image }}" class="img-circle" alt="Avatar"/>
        {% endif %}
        <p>{{ app.user }}</p>
    </li>

    <li class="user-body">
    </li>

    <li class="user-footer">
        <div class="pull-left">
            <a href="{{ _profile_uri }}" class="btn btn-default btn-flat"><i
                        class="fa fa-user"></i> {{ _profile_text }}</a>
        </div>

        <div class="pull-right">
            <a href="{{ _logout_uri }}" class="btn btn-default btn-flat"><i
                        class="fa fa-sign-out fa-fw"></i> {{ _logout_text }}</a>
            </div>
        </li>
    {% endif %}
{% endblock %}

但我诚实地认为最好实现SonataUserBundle并将其与FOSUserBundle和FOSOauthServerBundle一起使用。

答案 1 :(得分:0)

我认为这种行为是由SonataUserBundle处理的,你必须安装它,如果你在Sonata用户介绍中看到你可以看到这个包启用了用户配置文件,我认为这个用户图标。

Sonata User Bundle