简体   繁体   中英

How to have two list with one admin class sonata admin bundle

Can you help to configure two list in one class Admin so I need to override this function two times :

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->add('id', null, array(
            'header_style' => 'width: 5%; text-align: center',
            'row_align' => 'center'
        ))
        ->add('nom', null, array(
            'header_style' => 'width: 35%; text-align: center',
            'row_align' => 'center'
        ))  
        ->add('dateCreation', null, array(
            'header_style' => 'width: 35%; text-align: center',
            'row_align' => 'center'
        ));
}

See my answer here for how to configure custom filtered lists https://stackoverflow.com/a/41143235/5758328 in your admin menu.

If you really want to have two separate configureListFields() method what you can do is make a second admin for the same entity.

like so:

app.admin.bar:
    class: AppBundle\Admin\BarAdmin
    arguments: [~, AppBundle\Entity\Bar, BlastCoreBundle:CRUD ]
    tags:
        - name: sonata.admin
          manager_type: orm
          group: admin

 app.admin.bar2:
    class: AppBundle\Admin\BarAdmin2
    arguments: [~, AppBundle\Entity\Bar, BlastCoreBundle:CRUD ]
    tags:
        - name: sonata.admin
          manager_type: orm
          group: admin

Then just create the second admin class and do whatever you want with it.

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