symfony:带有一个参数的表单 [英] symfony : Form with one parameter
本文介绍了symfony:带有一个参数的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单,我想传递一个必须用来填充小部件的参数。
I have a form, and I want to pass it one parameter which must use to fill a widget.
我在我的url中传递参数:
I pass the parameter in my url :
url_for('myModule/new?parameter='.$myParam)
我尝试在我的动作中使用参数并将其显示在我的模板中,但它无效。
I have tried to take the parameter in my action and display it in my tamplate, but it doesn't work.
操作:
Action :
$this->param = $request->getParameter('parameter');
模板:
Template :
echo param;
但我无法在表单中找到它。
But I can't recover it in my form.
我该怎么做?
推荐答案
如果参数是对象的属性,您可以这样做:
If the parameter is an attribute of the object, you can do :
$object = new Class();
$object->setAttribute($request->getParameter('myParam'));
$form = new ClassForm($object);
这篇关于symfony:带有一个参数的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文