Adding a custom form inside the show template of a Sonata Admin Entity

我与影子孤独终老i 提交于 2019-12-05 02:50:10

The _sonata_admin (route) attribute is used by SonataAdminBundle to get the required admin instance ($this->admin) and be able to configure/process your requests:

After to add the right route definition:

protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('approve_order', $this->getRouterIdParameter().'/approve');
}

You need to add also the _sonata_admin code to generate the right request to approveOrderAction():

{{ render(controller('QiBssFrontendBundle:PmodOrderCRUD:approveOrder', { 'id': object.id, '_sonata_admin': '...' })) }}

Let's make a simple example:

You have an Order entity and its admin class: OrderAdmin into PurchaseBundle, so this is the Sonata's service definition for OrderAdmin class (Yaml):

services:
    purchase_bundle.admin.order_admin:
        class: PurchaseBundle\Admin\OrderAdmin
        arguments:
            - ~
            - PurchaseBundle\Entity\Order
            - ~
        tags:
            - { name: 'sonata.admin', manager_type: orm }

Now, based on your own approveOrderAction(), you can render this action in the follows way:

{{ render(controller('PurchaseBundle:OrderAdmin:approveOrder', { 'id': object.id, '_sonata_admin': 'purchase_bundle.admin.order_admin' })) }}

Just you have to add the admin code: 'purchase_bundle.admin.order_admin' and it should work!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!