教义和symfony过滤器,调试过滤器 [英] Doctrine and symfony filter, debug the filter
问题描述
所以我有以下过滤器:
class ClientFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
return $targetTableAlias.'client_id = '. $this->getParameter('client_id');
}
}
并在我的控制器中:
$em = $this->get('doctrine.orm.default_entity_manager');
$filter = $em->getFilters()->enable('client_filter');
var_dump($em->getFilters()->isEnabled('client_filter'));
打印出 bool(true)
意味着它已启用,但是当我从symfony探查器查看主义sql命令时,在 WHERE
语句
it prints out bool(true)
which means it is enabled, but when i look into the doctrine sql commands from symfony profiler i can't see the client_id in the WHERE
statment
我无法全局设置它,因为我仅在登录后才需要它。所以问题是,我如何检查过滤器是否正常工作?而另一面的问题是,如果我全局设置它,是否有一种方法只能使它在登录后才能工作,因为用户表中没有client_id,并且由于在登录后才添加客户端ID,这会导致错误,具体取决于哪个用户登录。
And i can't set it globally because i only need it after login. So the question will be, how can i check if the filter is working or not? and the other side question will be if i set it globally is there a way to only make it work after login because the user table doesnt have a client_id and it gives an error since the client id is only added after login depends on which user will login.
ps我要在登录后将client_id添加到会话中!
p.s i am adding the client_id to the session after login!
推荐答案
因为我是如此转储,所以我正在回答这个问题
I am answering this since i was so dump
代码中缺少2件事:
- $filter->setParameter('client_id',1); // 1 i usually get it from session
- and the actual call to some function to call a db table after that code i had nothing applied but the rendering of twig template.
控制器中的代码现在看起来像这样:
the code in controller looks like this now:
$this->get('somerepository')->findOneById(1);
这篇关于教义和symfony过滤器,调试过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!