Javascript symfony 4-如何在5秒钟后清除flash消息?
渲染细枝模板时,我正在控制器中设置一条flash消息。我正在检查用户电子邮件是否存在于数据库中,闪存将为绿色,否则为红色。 我想在5秒钟后清除信息闪烁,但不知如何清除 twig.htmlJavascript symfony 4-如何在5秒钟后清除flash消息?,javascript,symfony,symfony-forms,symfony4,symfony-3.4,Javascript,Symfony,Symfony Forms,Symfony4,Symfony 3.4,渲染细枝模板时,我正在控制器中设置一条flash消息。我正在检查用户电子邮件是否存在于数据库中,闪存将为绿色,否则为红色。 我想在5秒钟后清除信息闪烁,但不知如何清除 twig.html {#=======================( )===========================#} {#====================( )========================#} {#=================( flash message
{#=======================( )===========================#}
{#====================( )========================#}
{#=================( flash messages )=====================#}
{#====================( )========================#}
{#=======================( )===========================#}
{% for message in app.flashes('notice') %}
{% if var %}
<div class="flash-notice" style="background-color:red;">
{{ message }}
</div>
{% else %}
<div class="flash-notice" style="background-color:green;">
{{ message }}
</div>
{% endif %}
{% endfor %}
您需要编写一个javascript函数来删除
。在页面加载后5秒钟内发出flash通知。我想您想在5秒钟后隐藏/淡出消息而不清除?因为它在下一页重新加载后被清除。谢谢,我解决了这个问题
/**
* @Route("/find_email", name="find_email")
*/
public function FindEmail(Request $request,EventDispatcherInterface $eventDispatcher)
{
$user = new User();
$email = $request->request->get("inputEmail", "valeur par défaut si le champ n'existe pas");
$user = $this->getDoctrine()
->getRepository(User::class)
->findOneBy(['email' => $email]);
////////////////////////////////////
if (!$user) {
$var=true;
$this->addFlash("notice", "This is an error message");
} else {
$user_=$user;
$var=false;
$this->addFlash("notice", "This is a success message");
}
return $this->render('Security/reset_password.html.twig',[
'form'=> $email,
'var'=>$var,
]);
}