普通网友 2012-03-30 23:25
浏览 49

Symfony2相当于before_filter?

Just wondering if Symfony2 has an equivalent to before_filter from Rails? I want to alter the layout of my application based on the type of user that is viewing it. Thanks a lot.

EDIT: I should clarify my question. I want to alter the layout of my application based on a URL parameter. So ultimately all the before_filter equivalent has to do is make every template rendered by the controller inherit from a different base template based on that URL parameter. I should add I already have over 50 controller actions that render templates so ideally the solution should be something that is easy to enable application-wide without having to edit every controller action.

  • 写回答

2条回答 默认 最新

  • dongzi5062 2012-03-31 05:52
    关注

    I don't know that function but you can try {% if is_granted('ROLE_XXX') %} in twig templates or $this->get('security.context')->isGranted('ROLE_ADMIN') in the controller

    You'll find more information in http://symfony.com/doc/current/book/security.html.

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害