我使用Symfony 2.8.16和FOSUserBundle 1.3.7 fos用户管理。在"app/Resources"文件夹中,我有一个"FOSUserBundle"文件夹来替换FOSUserBundle模板为我的模板。目前,在mywebsite.com/login路径上有一个登录页面。在我的网站的其他公共页面上,我想在每个页面的顶部放置一个小型登录表单。我该如何做?在app/Resources/config/routing.yml中。
index:
path: /index
defaults: { _controller: MyBundle:MyController:MyAction }
##################
# FOS User Bundle
##################
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
在app/Resources/FOSUserBundle/views/security/login.html.twig中
{% extends ": MyLayout.html.twig" %}
{% block fos_user_content %}
{% if error %}
<div class="alert alert-danger">{{ error|trans({}, 'FOSUserBundle') }}</div>
{% endif %}
<form action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
<div class="row">
<div class="form-group col-m-6">
<input type="text" class="_username" id="_username" name="_username" value="{{ last_username }}" placeholder="Email ou identifiant" required="required" />
</div>
<div class="form-group col-m-6">
<input type="password" class="_password" id="_password" name="_password" placeholder="Mot de passe" required="required" />
</div>
</div>
<div class="form_action">
<button type="submit" class="button button-default-outline" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}">Connexion</button>
<div class="__sub">
<label class="remember">
<input type="checkbox" id="remember_me" name="_remember_me" checked> {{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}
<span class="separator">|</span>
<a href="#" class="forgot">Mot de passe oublié ?</a>
</label>
</div>
</div>
</form>
{% endblock fos_user_content %}