2012-06-21 16 views
0

我是Symfony的新手。有沒有辦法讓TWIG訪問安全配置文件中的頁面access_control設置?

我想要一段代碼只顯示在公開的網頁上。 Twig能夠檢測頁面是否公開?

該頁面在IS_AUTHENTICATED_ANONYMOUSLY下,但我仍然希望顯示一段代碼,即使用戶已經登錄。

For Example: 
www.somesite.com (shows the code, publicly available) 
www.somesite.com/login (user login, publicly available, shows code) 
//user is not logged in 
www.somesite.com/dosomething (only available to logged-in users, code is hidden) 
//user goes to the home page, still logged-in 
www.somesite.com (must show the code, publicly available) 

我知道我可以手動包含我的公共頁面的代碼,但有沒有辦法自動檢測頁面是否在防火牆之外?

請幫忙。 =)

回答

1

可以隱藏枝模板的部位,象這樣一個檢查:

{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %} 
    {# stuff only logged in users can see #} 
{% endif %} 
+0

對不起,我修改了這個問題,使其更清晰。希望你得到了答案=) – bernardnapoleon

相關問題