简体   繁体   中英

Symfony SonataAdminBundle - using a different entity for list/create in the same admin module

I am relatively new to sonata and I need to implement a new Admin module with a similar structure to following: Lets say I have a typical Shopping Cart scenario where I have an Order entity and an OrderItem, (one to many relation).

In The List view, It should display all the order items, but in the Create action, it will allow to create a Order entity (with an embeded form for creating order items).

Do I need to create 2 admin modules? If yes, how can change the "create" button to point to the other admin?

Thanks for your help.

You create you'r entities, Order and OrderItem. Then you need to create a specefic Admin Class for each. When you build the Order form mapper, you need to embed the order item collection, something like this should do the job:

->with('OrderItem')
                ->add('orderItem', 'sonata_type_collection', array(
                    'label' => 'Item',
                    'required' => true,
                    'allow_add' => true,
                    'allow_delete' => true,
                    'by_reference' => false,
                ),array(
                    'edit' => 'inline',
                    'inline' => 'table',
                    'sortable' => 'position',
        ))

I dont get it, why whould you change the create button ?

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