symfony2:twig扩展名is_granted('EDIT',comment)在foreach循环中不起作用

时间:2012-03-30 17:00:10

标签: symfony acl twig

官方ACL示例的代码有效:http://symfony.com/doc/current/cookbook/security/acl.html

如果我这样做,没问题......

{% if is_granted('EDIT', comment) %}
    Edit
{% endif %}

...但如果我想要一个关联对象的“授予访问权限”,它就不起作用。

{% for comment in news.comments %}
    comment.content
    {% if is_granted('EDIT', comment) %}
        Edit
    {% endif %}
{% endfor %}

我认为枝条扩展不能知道“评论”是“评论实体”。

查询搜索“Proxies \ JblNewsBundleEntityCommentProxy”而不是“Jbl \ NewsBundle \ Entity \ Comment”:

SELECT a.ancestor_id FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id INNER JOIN acl_object_identity_ancestors a ON a.object_identity_id = o.id WHERE ((o.object_identifier = '38' AND c.class_type = 'Proxies\\JblNewsBundleEntityCommentProxy'))

但我不知道如何解决这个问题。

请问你有解决方案吗?

1 个答案:

答案 0 :(得分:9)

它已在symfony 2.1 中修复。

对于旧的 2.0 版本,此修复程序位于此处:

Overriding the ObjectIdentityRetrievalStrategy to check if a domain object is a Doctrine proxy