我有一个表单,我想在我的网站的几个页面中使用。 所以我呼吁这样的方法在我的网页:Symfony2呈现和表单
{{ render(controller('ProjectApplicationBundle:Application:form')) }}
我有我的formAction方法:
public function formAction()
{
$form = $this->createForm($type,$obj);
if('POST' == $this->getRequest()->getMethod()){
$form->submit($this->getRequest());
if($form->isValid()){
//redirect to a page after the form
}
}
//render the form template ...
}
这不是我的代码,这只是一个例子。
所以我加入到创建一个路由送我的形式
project_application_form:
pattern: /form
defaults: { _controller: ProjectApplicationBundle:Application:form }
现在我的问题:)
1)我想使用的URL阻止访问我的形式,只允许进行数据处理。
2)如果错误的页面不重定向,所以窗体显示没有布局,所以我想在窗体的页面中显示错误的形式。
编辑:我可能有第二点的解决方案,但这不是很合适。 在我的参数中设置渲染路线并返回到路线而不是呈现渲染窗体。最后,我使用会话来输入错误。
我希望这对你很清楚,对不起我的英语。
你是什么意思通过阻止访问表单并只允许数据处理?您是否想让路由仅可用于POST请求? – nifr
好像你必须在你需要的所有控制器动作中使用你的formtype – sergekv