2017-05-10 132 views
1

我創建了自定義控制器(擴展了Sonata \ AdminBundle \ Controller \ CRUDController)和操作。無法在SonataAdminBundle模板中使用渲染器(控制器)

當呈現這個動作{{render(controller('MainBundle:SonataAdmin/Order:searchCertificate'))}}

我得到Symfony的錯誤:

An exception has been thrown during the rendering of a template ("There is no _sonata_admin defined for the controller MainBundle\Controller\SonataAdmin\OrderController and the current route").

回答

1

我發現在官方documentation答案:

If you want to render a custom controller action in a template by using the render function in twig you need to add _sonata_admin as an attribute. For example; {{ render(controller('AppBundle:XxxxCRUD:comment', {'_sonata_admin': 'sonata.admin.xxxx' })) }}. This has to be done because the moment the rendering should happen the routing, which usually sets the value of this parameter, is not involved at all, and then you will get an error "There is no _sonata_admin defined for the controller AppBundleControllerXxxxCRUDController and the current route ' '."