有没有办法在 SQLFilter 中访问 symfony2 容器? [英] Is there a way to access the symfony2 container within an SQLFilter?

查看:24
本文介绍了有没有办法在 SQLFilter 中访问 symfony2 容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在 SQLFilter 中获取 symfony2 的服务容器,或者我可以直接将服务用作 SQLFilter?

is there any possibility to get the service-container of symfony2 within an SQLFilter or can i maybe directly use a service as SQLFilter?

我知道这不是一种干净"的方式,但我必须在查询的最终提交被触发之前直接执行几次检查(因为我必须将条件附加到 WHERE 语句,我不能此时使用生命周期事件).

I know that this isn't a "clean" way, but i have to perform several checks directly before the final submit of the query gets fired (as i have to append conditions to the WHERE-statement, i can't use lifecycle-events at this point).

推荐答案

不干净但你可以试试这个:

it's not clean but you could try this:

<?php

class MyBundle extends Bundle 
{
public function boot()
{
    $em = $this->container->get('doctrine.orm.default_entity_manager');
    $conf = $em->getConfiguration();
    $conf->addFilter(
        'test',
        'DoctrineFilterTestFilter'
    );

    $em->getFilters()->enable('test')->setContainer($this->container);
}
}

这篇关于有没有办法在 SQLFilter 中访问 symfony2 容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆