I need to implement a form inside my show template of a specific admin. In the original demo of Symfony a great example is shown. Please take a look at it here;
- Controller (look at the method on line 120 as well)
- Post Show template
- Comment Form template
Now what I've done in Sonata;
I've created the custom CRUD Controller for the specific admin class (OrderAdmin). I already have a clone action there that works well, so I know my custom CRUD Controller works perfect.
I also have a custom show template specific for OrderAdmin. Again that works well, because I already have something custom there.
Now for my work relating to this custom comment form;
My action just to render the form (like in the Symfony demo):
/**
* @param Order $order
* @return \Symfony\Component\HttpFoundation\Response
*/
public function commentFormAction(Order $order)
{
$form = $this->createFormBuilder()
->add('comment')
->getForm();
return $this->render('AppBundle:Order:_comment_form.html.twig', array(
'order' => $order,
'form' => $form->createView(),
));
}
A snippet of my show template:
<div class="row">
<div class="col-md-12">
{{ render(controller('AppBundle:OrderCRUD:commentForm', { 'id': object.id })) }}
</div>
</div>
and finally my _comment_form template where the form self is rendered:
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn btn-primary pull-right" type="submit">Comment</button>
{{ form_end(form) }}
I'm pretty sure this is all setup fine, the only problem I get is that...
An exception has been thrown during the rendering of a template ("There is no
_sonata_admin
defined for the controllerAppBundle\Controller\OrderCRUDController
and the current route ``").
I have another action that will be the comment form action, but I get the problem here before that action is called on form submission.
Can somebody please help me understand this _sonata_admin
. How do I define it? What should I had to my code, or how do I have to change it to get a form function properly in my show template. Does anybody have an example of how to accomplish this? I've come across a few posts over the web where people struggle with this.
I've also started a bounty on this question with a very very similar issue.
I desperately need help to get this to work. Please? I know Sonata support is quite poor but I need you guys, please.