在将网站迁移到symfony时,我必须重用一些HTML代码。当前的HTML页面有一个表单:
<form name="n1" id="n1" method="post" onsubmit="return verifSelect()" action="{{path('toto')}}" >
<select>
{% for e in experimentations %}
<option>{{e.name}}</option>
{% endfor %}
</select>
</form>
我想将所选的Experimentation
对象(不仅是名称)传递给toto
页面。 The symfony doc uses something like:
if ($form->isSubmitted() && $form->isValid()) {
// ... perform some action, such as saving the task to the database
return $this->redirectToRoute('task_success');
}
但我有两个问题:
form
对象引用?experimentation
对象引用(以便将其作为参数发送到下一条路径)?非常感谢你的帮助,
答案 0 :(得分:0)
我不确定我理解你的问题,但我会尽力给你答案:
你可以这样做:
_heightConstraint.constant = 650;
[_myview layoutIfNeeded];
然后你可以在你的totoAction上获得实验ID。
我希望它可以帮到你。
答案 1 :(得分:0)
首先,您必须为您的选择标记指定一个名称,以便您可以引用它name="experimentations"
。你还需要一个提交按钮,我猜你有<input type="submit" value="submit"/>
<form name="n1" id="n1" method="post" onsubmit="return verifSelect()" action="{{path('toto')}}" >
<select name="experimentations">
{% for e in experimentations %}
<option>{{e.name}}</option>
{% endfor %}
</select>
<input type="submit" value="submit"/>
</form>
要获取控制器类中的信息,请使用$request
- 对象。
功能
class DefaultController extends Controller {
/**
*
* Matches /todo/
*
* @Route("/todo/", name="Todo")
*/
public function indexAction(Request $request) {
$experimentations = $request->request->get("experimentations");
...
}
据我所知,在这种情况下你不能使用form-Object,但是人们可能会纠正我......