在控制器中:
$entity = new Goods();
$form = $this->createForm(new GoodsType(), $entity, array(
'action' => $this->generateUrl('shop_goods_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $this->render('ShopAdminBundle:Goods:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
在视图中: 我想得到动作网址。它就像表格形式(form.action),我知道这是错的,希望谁能告诉我一个正确的方法
答案 0 :(得分:0)
您可以在Controller操作中返回表单操作网址,例如:
return $this->render('ShopAdminBundle:Goods:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
'actionUrl' => $this->generateUrl('shop_goods_create');
));
然后在树枝中,您可以使用{{ actionUrl }}
如何生成网址:http://symfony.com/doc/current/book/routing.html#generating-urls