2014-09-01 98 views
0

使用单一的调用方式操作在控制器:我怎么能在树枝

$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(), 
    )); 

在View: 我想获得操作URL。这就像表格形式(form.action),我知道这是不对的,希望谁可以告诉我一个正确的方法

回答

0

你可以在你的控制器动作回执操作URL,如:

return $this->render('ShopAdminBundle:Goods:new.html.twig', array(
    'entity' => $entity, 
    'form' => $form->createView(), 
    'actionUrl' => $this->generateUrl('shop_goods_create'); 
)); 

然后在树枝可以使用{{ actionUrl }}

如何生成URL让你的表单操作:http://symfony.com/doc/current/book/routing.html#generating-urls

+0

好吧,我只是想知道是否$这个 - >的CreateForm()调用表单模板(form.action)方法类似。但是Thx〜 – 2014-09-01 09:20:01