Symfony2 - SonataAdmin - 清空admin_list块

时间:2013-07-28 18:43:33

标签: php symfony sonata-admin symfony-sonata

我一直在尝试安装SonataAdminBundle。我想我遵循了文档,而且我读了一些关于它的博客。但我做不到。

当进入管理员/仪表板页面时,我看到Sonata标题,我可以看到右边的sonata.block.service.text和sonata.block.service.rss,但是admin_list块中没有任何内容=>我看不到我的实体。

以下是我如何设置它。我可能忘了什么? 这是app / config / config.yml

imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: ../../src/Pierre/TennisBundle/Resources/config/admin.yml }

...

sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts:   [admin]

        sonata.block.service.text:
        sonata.block.service.rss:

sonata_doctrine_orm_admin:
    # default value is null, so doctrine uses the value defined in the configuration
    entity_manager: '@doctrine.orm.entity_manager'

    templates:
        form:
            - SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig
        filter:
        - SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig
        types:
            list:
                array:      SonataAdminBundle:CRUD:list_array.html.twig
                boolean:    SonataAdminBundle:CRUD:list_boolean.html.twig
                date:       SonataAdminBundle:CRUD:list_date.html.twig
                time:       SonataAdminBundle:CRUD:list_time.html.twig
                datetime:   SonataAdminBundle:CRUD:list_datetime.html.twig
                text:       SonataAdminBundle:CRUD:base_list_field.html.twig
                trans:      SonataAdminBundle:CRUD:list_trans.html.twig
                string:     SonataAdminBundle:CRUD:base_list_field.html.twig
                smallint:   SonataAdminBundle:CRUD:base_list_field.html.twig
                bigint:     SonataAdminBundle:CRUD:base_list_field.html.twig
                integer:    SonataAdminBundle:CRUD:base_list_field.html.twig
                decimal:    SonataAdminBundle:CRUD:base_list_field.html.twig
                identifier: SonataAdminBundle:CRUD:base_list_field.html.twig

            show:
                array:      SonataAdminBundle:CRUD:show_array.html.twig
                boolean:    SonataAdminBundle:CRUD:show_boolean.html.twig
                date:       SonataAdminBundle:CRUD:show_date.html.twig
                time:       SonataAdminBundle:CRUD:show_time.html.twig
                datetime:   SonataAdminBundle:CRUD:show_datetime.html.twig
                text:       SonataAdminBundle:CRUD:base_show_field.html.twig
                trans:      SonataAdminBundle:CRUD:show_trans.html.twig
                string:     SonataAdminBundle:CRUD:base_show_field.html.twig
                smallint:   SonataAdminBundle:CRUD:base_show_field.html.twig
                bigint:     SonataAdminBundle:CRUD:base_show_field.html.twig
                integer:    SonataAdminBundle:CRUD:base_show_field.html.twig
                decimal:    SonataAdminBundle:CRUD:base_show_field.html.twig

sonata_admin:
    security:
        handler: sonata.admin.security.handler.role

    title:      Sonata Project
    title_logo: /bundles/sonataadmin/logo_title.png
    templates:
        # default global templates
        layout:  SonataAdminBundle::standard_layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig
        dashboard: SonataAdminBundle:Core:dashboard.html.twig

        # default actions templates, should extend a global templates
        list:    SonataAdminBundle:CRUD:list.html.twig
        show:    SonataAdminBundle:CRUD:show.html.twig
        edit:    SonataAdminBundle:CRUD:edit.html.twig

    dashboard:
        blocks:
            # display a dashboard block
            - { position: left, type: sonata.admin.block.admin_list }

            # Customize this part to add new block configuration
            - { position: right, type: sonata.block.service.text, settings: { content: "<h2>Welcome to the Sonata Admin</h2> <p>This is a <code>sonata.block.service.text</code> from the Block Bundle, you can create and add new block in these area by configuring the <code>sonata_admin</code> section.</p> <br /> For instance, here a RSS feed parser (<code>sonata.block.service.rss</code>):"} }
            - { position: right, type: sonata.block.service.rss, settings: { title: Sonata Project's Feeds, url: http://sonata-project.org/blog/archive.rss }}

        groups:
            sonata_page:
                label: TestLabel
                items: ~



    # set to true to persist filter settings per admin module in the user's session
    persist_filters: true

我的管理员课程

namespace Pierre\TennisBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

use Pierre\TennisBundle\Entity\Tennismen;

class TennismenAdmin extends Admin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('name')
               ;
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('name')
               ;
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
                ;
    }
}

我的控制器:

namespace Pierre\TennisBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as Controller;

class TennismenAdminController extends Controller
{
}

我的服务:

# TennisBundle/Resources/config/admin.yml
services:
    pierre.tennis.admin.tennismen:
        class: Pierre\TennisBundle\Admin\TennismenAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: sonata_page, label: Blog }
        arguments: [null, Pierre\TennisBundle\Entity\Tennismen, PierreTennisBundle:TennismenAdmin]

所以我认为我尊重指南...但我无法在仪表板中看到我的实体网球员。

3 个答案:

答案 0 :(得分:3)

但在某些情况下,向所有用户授予SUPER_ADMIN角色不是解决方案,请确保在yout parameters.yml中包含此行:

security.acl.permission.map.class: Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap

答案 1 :(得分:2)

您可以尝试SonataAdminBundle:CRUD作为服务定义中的第三个参数吗?此外,请确保您已使用超级管理员登录(如果您安装了SonataUserAdmin)。另外,请尝试删除dashboard中的config.yml部分,或尝试尽可能少地使用配置。

答案 2 :(得分:0)

我能解决它,谢谢你! 我必须将FOSUser SUPER_ADMIN角色添加到我的用户才能看到admin_block。

谢谢!