Is there a smarter way to disable Doctrine2 filters in Symfony2.1?

I'm using Gedmo Doctrine Extensions, such as SoftDeletable, and at various points I need to disable this filter so that users can interact with soft deleted entities, or soft deleted relations of an entity.

This includes but is not limited to, once in a controller and again in a specific area of the SonataAdmin.

So far the solution I've found is to call getFilters() on the em and disable softdeleteable, which is fine.

However both sonata admin classes and controllers seem to go through multiple executions, which causes a fatal attempting to disable an already disabled filter, so I have to do this:

    if (array_key_exists('softdeleteable', $this->em->getFilters()->getEnabledFilters())) {
        $this->em->getFilters()->disable('softdeleteable');
    }

Which seems itself hacky to say the least.

But also, there are other problems, such as scoping of the command. I haven't spotted any problems frontend yet, but in the admin, the multiple executions, one of which is to build the navigation (I think) means that the filter is always disabled, and only being able to do this directly on the em seems to me like it will cause a hell of a load of issues as soon as I don't want the functionality disabled somewhere backend.

Is there a better way of doing this?


Whilst at the time of writing, the answer was no, the functionality to disable filters on a per-entity basis has now been added, like so:

// Enable / Disable filter filter, for specified entity (default is enabled for all)
$filter = $em->getFilters()->enable('soft-deleteable');
$filter->disableForEntity('EntityArticle');
$filter->enableForEntity('EntityArticle');

Documentation: https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/softdeleteable.md

链接地址: http://www.djcxy.com/p/11160.html

上一篇: Google网络字体存储在本地与在线来源中

下一篇: 有没有更聪明的方法来禁用Symfony2.1中的Doctrine2过滤器?