Customize Authentication - Login Symfony2 Messages

后端 未结 2 1724
慢半拍i
慢半拍i 2020-12-03 03:09

So I\'m reading the security chapter of Symfony2 Book. I understand everything, but I\'d like to customize the error message if a there is a login error.

In which fi

相关标签:
2条回答
  • 2020-12-03 03:47

    There is another possibility if you don't want to use translations. You can just replace the message, for example:

    {{ error.message | replace({"Bad credentials." : "Invalid username or password."}) }}
    
    0 讨论(0)
  • 2020-12-03 04:01

    You can use translation. In parameters.ini set locale to your language and create message file. Then in twig template use:

    {% if error %}
        <div class="error">{{ error.message|trans({},'messages') }}</div>
    {% endif %}
    
    0 讨论(0)
提交回复
热议问题