2014-09-01 97 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