提交表单后未刷新的 Symfony Flash 消息和数据



我正在使用模态表单来更新地址。除了提交表单后不显示 Flash 消息或更新视图数据并因此重新加载页面外,一切都正常工作。要显示消息并更新数据,我必须手动刷新页面。

在我看来,这是模态形式的调用:

...
{{ include('_flashMessages.html.twig') }}
...
<a href="#profileAddress" data-toggle="modal" data-target="#profileAddress">Edit</a>
...
<div id="profileAddress" tabindex="-1" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Profile address</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
{{ render(controller('App\Controller\user\ProfileController::editAddress', { 'advert': advert.id, 'request': app.request })) }}
</div>
</div>
</div>
</div>
...

下面是调用的用于呈现表单的函数:

/**
* @Route("/user/profile/show/{id}", name="user.profile.show")
* 
* @return Response
*/
public function show(User $user): Response
{
$profile = $user->getProfile();
return $this->render('user/profile/show.html.twig', array(
'profile' => $profile,
'bodyId' =>  'profileShow'
)
)
;
}

最后,这是我链接到我的表单以重定向到初始视图的操作:

{{ form_start(form, { 'action': absolute_url(path('advert.vehicle.create', { 'id': advert.id })), 'attr': { 'id': 'profileAddressForm' } }) }}
...

有人知道在初始视图中未显示闪烁消息和地址数据未更新的原因吗?

提前感谢您的帮助。

编辑:

我解决了 2 个问题中的 1 个:通过将我的模态div 放在模板的开头,提交表单后现在可以正确显示成功闪烁消息。

现在仍然需要理解为什么通过使用上述表格正确更新的数据在我看来没有刷新。确实,在这一点中,我有:

...
{% set profileAddress = advert.owner.user.profile.address.street %}
...
<div class="row">
<div class="col-md-10">
{{ form_row ( vehicleForm.situation.useProfileAddess, { 'id':'use_profil_address', 'label': "Use my profile address (" ~ profileAddress ~ ")" } ) }}
</div>
<div class="col">
<a href="#" data-focus=true data-backdrop="static" data-keyboard="false" data-toggle="modal" data-target="#profileAddress">Edit</a>
</div> 
</div>
...

表单会更新数据库中的地址数据,但在提交表单后重新加载页面时,不会在视图中刷新这些数据。

解决者

{% set profileAddress = advert.owner.user.profile.address %}

{{ form_row ( vehicleForm.situation.useProfileAddess, { 'id':'use_profil_address', 'label': "Use my profile address (" ~ profileAddress.street ~ ")" } ) }}

最新更新