简体   繁体   中英

Symfony2 - SonataAdmin - Empty admin_list block

I have been trying to install SonataAdminBundle. I think I followed the documentation, plus I read some blogs about it. But I couldn't do it.

When going to the admin/dashboard page, i see the Sonata Title, i can see the sonata.block.service.text and the sonata.block.service.rss on the right, but there is nothing in the admin_list block => I can't see my Entity.

Here is how I set it up. I maybe forgot something ? Here is the 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

My admin class

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')
                ;
    }
}

My Controller:

namespace Pierre\TennisBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as Controller;

class TennismenAdminController extends Controller
{
}

And my service:

# 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]

So I think i respected the guide... but I can't see my Entity Tennismen in the dashboard.

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

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

Can you try SonataAdminBundle:CRUD as your third argument in the service definition? Also, ensure you have logged in with super admin (if you have SonataUserAdmin installed). Also, try removing dashboard part in your config.yml or try using as little configuration as possible all together.

I Could solve it thanks to you ! I had to add the FOSUser SUPER_ADMIN role to my user to be able to see the admin_block.

Thanks!

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