我想在奏鸣曲管理员演示模板中生成一个小窗体。我迄今为止所做的是在自定义CRUD中为该特定实体(订单)创建功能,该功能从Sonata的默认CRUD扩展而来;在奏鸣曲管理实体的演示模板中添加自定义窗体
public function approveOrderAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$order = $this->admin->getObject($id);
$approveForm = $this->createFormBuilder($order)
->add('reqSecondApprover', 'checkbox', array('label' => 'Require second Approval', 'required' => false))
->add('secondApprover', 'choice', array('choices' => Crud::getWhatever(array('Developer')), 'required' => false))
->getForm();
$approveForm->handleRequest($request);
if ($approveForm->isSubmitted() && $approveForm->isValid()) {
$secondApproval = $request->request->get('form');
$approval = $approveForm->getData();
if (isset($secondApproval['reqSecondApprover'])) {
$order->setStatus(PmodOrder::STATUS_PARTLY_APPROVED);
} else {
$order->setStatus(PmodOrder::STATUS_APPROVED);
$order->setSecondApprover(null);
}
$em->persist($approval);
$em->flush();
return new RedirectResponse($this->admin->generateUrl('show'));
}
return $this->render('AppBundle:PmodOrder:order_approve.html.twig', array(
'order' => $order,
'form' => $approveForm->createView(),
));
}
在我的订单中我有configShowFields
方法;
protected function configureShowFields(ShowMapper $showMapper)
{
$order = $this->getSubject();
$showMapper
->with('General')
->add('createdBy', null, array('label' => 'Requested By'))
->add('createdAt', null, array('label' => 'Date Requested'))
->with('Order Details')
->add('orderRows', NULL, array('template' => 'AppBundle:PmodOrderRow:orderrow_overview.html.twig'))
->end()
->with('Actions')
->add('actions', NULL, array('template' => 'AppBundle:PmodOrderAction:order_actions.html.twig', 'route' => 'approve'))
->end()
;
}
的order_actions
模板看起来是这样的,并会显示相关的功能根据订单的状态,谁登录了,所以怎么有这么多diffent路线工作?;
<td>
{% if app.user.id == object.firstApprover and object.status == 1%}
{{ render(controller('AppBundle:PmodOrderCRUD:approveOrder', { 'id': object.id })) }}
{% elseif app.user.id == object.secondApprover and object.status == 2 %}
<a href="{{ path('order_second_approve', { 'id': object.id })}}" class="btn btn-primary"><i class="fa fa-check"></i> Approve</a>
<a href="{{ path('order_disapprove', { 'id': object.id })}}" class="btn btn-default"><i class="fa fa-times"></i> Disapprove</a>
{% elseif app.user == object.createdBy and object.status == 3 %}
<a href="{{ path('order_place', { 'id': object.id })}}" class="btn btn-primary">Place Order</a>
<a href="{{ path('order_place', { 'id': object.id })}}" class="btn btn-default">Cancel Order</a>
{% else %}
-
{% endif %}
</td>
尝试此操作时出现错误;
例外,已经模板 的呈现期间已经抛出(“没有用于控制器
ApBundle\Controller\PmodOrderCRUDController
和 当前路线``定义_sonata_admin
”)在 的appbundle:PmodOrderAction:order_actions.html.twig在线3.
我明白从documentation,我需要使用此configureRoutes
方法;
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('clone', $this->getRouterIdParameter().'/clone');
}
但我不能得到它的工作,我不知道如何呈现形式,而不是一个简单的链接按钮。
有人可以帮我解决我的问题吗?