[英]How get form in controller action Symfony 2
I trying to send Ajax request to my Controller, get form there, and if some data true, need to remove some part of form, but I dont know how i can get my form trought $request object. 我试图将Ajax请求发送到我的Controller,在那里获取表单,并且如果某些数据为真,则需要删除表单的某些部分,但是我不知道如何将我的表单放入$ request对象。 Help me please.
请帮帮我。
All code for now, I tell there is exist some way, to do something like this $request->getForm()
我告诉现在所有代码都存在某种方式,可以执行类似
$request->getForm()
public funcion ajaxAction(Request $request)
{
if ($request->isXmlHttpRequest()) {
}
}
You should do something like this (I assume you're in your controller extending Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller
): 您应该执行以下操作(我假设您在扩展
Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller
):
public funcion ajaxAction(Request $request)
{
if ($request->isXmlHttpRequest()) {
$form = $this->createForm(new YourFormType());
$form->handleRequest($request);
}
}
after that you have $form
with data from requst bound. 之后,您将
$form
带有来自请求绑定的数据的$form
。 You can call methods like isValid()
or getData()
on this variable 您可以在此变量上调用
isValid()
或getData()
类的方法
Check documentation for more info 查看文档以获取更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.