2013-08-16 32 views
0

我通過了http://tutorial.symblog.co.uk/index.html的symfony博客教程,並希望將其擴展爲需要驗證。我鬆散地遵循http://symfony.com/doc/current/cookbook/security/entity_provider.html,創建了一個新的Bundle(我想稍後將它提取到一個公共區域),並且事情工作正常。唯一的問題是,在登錄頁面上,它沒有顯示symfony工具欄(它在其他地方),但是頁面的其餘部分顯示爲我所期望的。登錄時缺少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> 
+0

除非生成完整的html頁面,否則滾動條不會顯示。在你的瀏覽器上進行控制。我希望你會看到一些HTML,然後可能是一個錯誤信息或切斷。反過來希望能指出問題。 – Cerad

+0

什麼都沒有被切斷。我聽說這是因爲工具欄在訪問權限下沒有正確設置,但我不完全確定如何執行此操作。這是我的security.yml: – Derek

回答

1

編輯:我找到了答案......看ACCESS_CONTROL下。

什麼都沒有被切斷。我聽說這是因爲工具欄在訪問權限下沒有正確設置,但我不完全確定如何執行此操作。這是我的security.yml:

security: 
    encoders: 
     Database\UserBundle\Entity\User: 
      algorithm:   sha1 
      encode_as_base64: false 
      iterations:   1 

    role_hierarchy: 
     ROLE_ADMIN:  ROLE_USER 
     ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 

    providers: 
     administrators: 
      entity: { class: DatabaseUserBundle:User, property: email } 

    firewalls: 
     login_firewall: 
      pattern: ^/login$ 
      anonymous: ~ 
     secured_area: 
      pattern: ^/ 
      anonymous: ~ 
      form_login: 
       login_path:      login 
       check_path:      login_check 
       always_use_default_target_path: true 
       default_target_path:   /
      logout: 
       path: /logout 
       target:/

    access_control: 
     - { path: /_wdt/.*, role: IS_AUTHENTICATED_ANONYMOUSLY } ### These 2 lines needed 
     - { path: /_profiler/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }### These 2 lines needed 
     - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/, roles: ROLE_USER } 
+0

好吧,我在http://forum.symfony-project.org/viewtopic.php?t=37865&p=125808找到了答案。該ACCESS_CONTROL需求: ACCESS_CONTROL: - {路徑:/_wdt/.*作用:IS_AUTHENTICATED_ANONYMOUSLY} - {路徑:/_profiler/.*作用:IS_AUTHENTICATED_ANONYMOUSLY} - {路徑:^ /登錄,角色:IS_AUTHENTICATED_ANONYMOUSLY } - {path:^ /,roles:ROLE_USER} – Derek