在基本模板base.html.twig我写了这段代码
{% if app.user %}
<a href="{{ path('logout') }}">Logout</a>
{% else %}
<a href="{{ path('register') }}">register</a> |
<a href="{{ path('login') }}">Login</a>
{% endif %}
在 /profile 中登录后 ,我在菜单中看到注销链接,但在 /(和其他页面)中,我在菜单中看到注册和登录链接
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: ^/