首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >自定义身份验证-登录Symfony2消息

自定义身份验证-登录Symfony2消息
EN

Stack Overflow用户
提问于 2012-02-09 05:36:33
回答 2查看 19.9K关注 0票数 19

所以我正在读Symfony2书的安全章节。我理解所有的东西,但是如果有登录错误,我想自定义错误消息。

我可以在哪个文件中更改此设置?

这是模板:

{% if error %}
    <div>{{ error.message }}</div>
{% endif %}

<form action="{{ path('login_check') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />

<label for="password">Password:</label>
<input type="password" id="password" name="_password" />

{#
    If you want to control the URL the user is redirected to on success (more details below)
    <input type="hidden" name="_target_path" value="/account" />
#}

<input type="submit" name="login" />

我认为最糟糕的方法是这样做:

if (error.message=="Bad credentials")
    echo "Los datos son erróneos :)"

if (error.message==The presented password is invalid")
    echo "La combinación username/password no es correcta :)"

你能帮我一下吗?

编辑:我让它工作了:

如果有人需要这样做,请确保将此行添加到config.yml

#app/config/config.yml
framework:
    translator: { fallback: en }

在文件messages.whateverisyourlanguage.yml中,在我的例子中是messages.es.yml,如下所示:

要翻译的文本:已翻译的文本

#Foo\DummyBundle\Resources\translations\messages.es.yml
The presented password cannot be empty.: El campo contrasena no debe estar vacio
The presented password is invalid.: Los datos suministrados son incorrectos
Bad credentials: Los datos suministrados son incorrectos

要小心处理要翻译的文本。如果文本的末尾有一个点,你必须把这个点放进去。我没有那样做,它也不起作用。

footranslate.footranslate不同

问候!:)

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9201849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档