我浏览了http://tutorial.symblog.co.uk/index.html上的 symfony 博客教程,并希望将其扩展为需要身份验证。我松散地遵循http://symfony.com/doc/current/cookbook/security/entity_provider.html,创建了一个新的 Bundle(我想稍后将它提取到一个公共区域)并且一切正常。唯一的问题是在登录页面上,它没有显示 symfony 工具栏(它在其他任何地方都显示),但页面的其余部分按我的预期显示。
有任何想法吗?提前致谢。
我的 login.html.twig:
{% extends '::base.html.twig' %}
{% block title %}Please Login{% endblock %}
{% block body %}
{% if error %}
<div class="error-message">{{ error.message }}</div>
{% endif %}
<form action="{{ path('login_check') }}" method="post">
<label for="username">E-mail address:</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" />
#}
<button type="submit">login</button>
</form>
{% endblock %}
我的 ::base.html.twig:
<!-- app/Resources/views/base.html.twig -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html"
; charset=utf-8" />
<title>{% block title %}symblog{% endblock %} - symblog</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
{% block stylesheets %}
<link href='http://fonts.googleapis.com/css?family=Irish+Grover' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=La+Belle+Aurore' rel='stylesheet' type='text/css'>
<link href="{{ asset('css/screen.css') }}" type="text/css" rel="stylesheet"/>
{% endblock %}
<link rel="shortcut icon" href="{{ asset('favicon.ico') }}"/>
</head>
<body>
<section id="wrapper">
<header id="header">
<div class="top">
{% block navigation %}
<nav>
<ul class="navigation">
<li><a href="{{ path('BloggerBlogBundle_homepage') }}">Home</a></li>
<li><a href="{{ path('BloggerBlogBundle_about') }}">About</a></li>
<li><a href="{{ path('BloggerBlogBundle_contact') }}">Contact</a></li>
{% if app.user %}
<li><a href="{{ path('logout') }}">Logout {{ app.user.username }}</a></li>
{% endif %}
</ul>
</nav>
{% endblock %}
</div>
<h2>{% block blog_title %}<a href="{{ path('BloggerBlogBundle_homepage') }}">symblog</a>{% endblock %}</h2>
<h3>{% block blog_tagline %}<a href="{{ path('BloggerBlogBundle_homepage') }}">creating a blog in
Symfony2</a>{% endblock %}</h3>
</header>
<section class="main-col">
{% block body %}{% endblock %}
</section>
<aside class="sidebar">
{% block sidebar %}{% endblock %}
</aside>
<div id="footer">
{% block footer %}
Symfony2 blog tutorial - created by <a href="https://github.com/dsyph3r">dsyph3r</a>
{% endblock %}
</div>
</section>
{% block javascripts %}{% endblock %}
</body>
</html>