【发布时间】:2014-08-30 19:09:46
【问题描述】:
我想在我的控制器中提取 Symfony2 表单的动作。 $form->getConfig()->getAction() 只返回一个空字符串。
还有其他方法吗?
public function fooAction(Request $request)
{
$bar = new BarEntity();
$form = $this->createForm(new BarType(), $bar);
$form->handleRequest($request);
$action = ''; // how to get the action?
return array('form' => $form->createView());
}
示例:
<form action="this/is/the/value/im/interested/in" enctype="...">...</form>
【问题讨论】:
-
@sebbo 对于我不清楚的问题,我深表歉意。我实际上对呈现的
<form></form>的 action 值感兴趣 -
$form->getConfig()->getAction();如果您设置了操作,它将起作用。默认情况下没有任何操作。您在模板中构建它,或者在构建表单时设置它。