我正在与bootbox 一起使用 symfony 2 呈现表单。所以当我想动态更改内容时我遇到了一个麻烦,我不知道如何。
所以这就是我想要的
- 我单击一个按钮,该按钮从嵌入模式对话框的控制器中呈现表单
<button class="btn btn-primary btn-new" data-toggle="modal" data-target="#agregarRonda">
Add My Entity
</button>
<div style="display: none;" class="modal fade" id="agregarRonda" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Add my Entity</h4>
</div>
<div class="modal-body">
{% embed "projete:MyEntity:newMyEntity.html.twig" %}
{% endembed %}
</div>
</div>
</div>
</div>
2.当我渲染一个表单 newMyentity.html.twig 时,它有一个按钮可以重定向到 symfony 上我的控制器内部的这个方法,例如:
public function createMyEntityAction(Request $request)
{
$user = $this->get('security.context')->getToken()->getUser();
$entity = new MyEntity();
$form = $this->createMyEntityForm($entity);
$form->handleRequest($request);
if ($form->isValid())
{
if( ifNotExist( $entity->getDescription() ) )
{
//Do the right things
}
else{
/*
* Return content to the modal dialog and don't hide modal dialog?
*/
}
}
}
所以,我调用一个方法 ifNotExist 来检查一些东西。如果返回 false 我希望将内容发送到模态对话框而不隐藏模态对话框并修改内容。
我该怎么做?
谢谢。