2013-04-25 3 views
1

base.html.twig 내가이 코드를 쓰기 로그인 정보에 액세스 할 수 없습니다Symfony2 : 진정한 형태의 작업 로그인,하지만 난 {{app.user}} 기본 템플릿에서

{% if app.user %} 
    <a href="{{ path('logout') }}">Logout</a> 
    {% else %} 
    <a href="{{ path('register') }}">register</a> | 
    <a href="{{ path('login') }}">Login</a> 
    {% endif %} 

로그인 후 에서/i를 등록하고 로그인 링크 내가 COU 어떻게

security: 
    ... 
    providers: 
     administartors: 
      entity: { class: DotArtBundle:User, property: username } 

    firewalls: 
     profile: 
      pattern: ^/profile 
      http_basic: ~ 
      anonymous: ~ 
      form_login: 
       check_path: /profile/login_action 
       login_path: /login 
       use_forward: false 
       username_parameter: _username 
       password_parameter: _password 
      logout: 
       path: /profile/logout 
       target:/
       invalidate_session: false 
     login: 
      pattern: ^/login 
      security: false 

    access_control: 
     - { path: ^/login,   roles: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/profile,  roles: ROLE_USER } 
     - { path: ^/profile/admin, roles: ROLE_ADMIN } 

메뉴에서 볼 수 난/(다른 페이지)에서 로그 아웃 메뉴 에 링크하지만 를 참조 프로파일 이 문제를 해결 했는가?

해결책 :

내가 인/로그 아웃 체크에있어서, pattern: ^/profile 쪽 끝에 pattern: ^/

답변

2

로 변경. is_granted를 사용하면 향후 업데이트에 대한 신뢰도가 높아집니다.

{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %} 
    <a href="{{ path('logout') }}">Logout</a> 
{% else %} 
    <a href="{{ path('register') }}">register</a> | 
    <a href="{{ path('login') }}">Login</a> 
{% endif %}