简体   繁体   中英

how to include an entity join in sonata bundle admin list view

related code:

in services.yml

sonata.admin.domain:
        class: MyBundle\AdminBundle\Admin\MyAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Domains", label: "Domains" }
        arguments:
            - ~
            - MyBundle\ServiceBundle\Entity\MyEntity
            - ~
        calls:
            - [ setTranslationDomain, [MyOtherBundle]]

in my admin controller:

 protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->add('domain')
            ->add('user.email')
            ->add('_action', 'actions', array(
                             'actions'  => array(
                                                 'show' => array())));

    }

which errors in:

Notice: Undefined index: user

to describe the problem further, i have a table that has a user_id column, and i want to be able to include the users email address (using fos user bundle) in that same list with that table. i've tried custom query with no luck also. thanks ahead of time

here is official documentation about list view definition :

http://sonata-project.org/bundles/admin/master/doc/reference/action_list.html

and

http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/list_field_definition.html

if you have a user_id within you entity, i guess your entity is an override of fosUserBundle, right ?

so normally you directly access from the list field definition like this :

->add('user.email') // user is you entity object

otherwise if it sa standalone entity with a user_id, you might have a relationship between this entity and the entity which owns your fosuserbundle object, and like in the above list field definition , you should normally access the object email.

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