Doctrine and symfony filter, debug the filter

旧时模样 提交于 2019-12-24 21:26:04

问题


So i have the following filter:

class ClientFilter extends SQLFilter
{
    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
    {
        return $targetTableAlias.'client_id = '. $this->getParameter('client_id');
    }

}

and in my controller:

$em = $this->get('doctrine.orm.default_entity_manager');
$filter = $em->getFilters()->enable('client_filter');
var_dump($em->getFilters()->isEnabled('client_filter'));

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

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.

p.s i am adding the client_id to the session after login!


回答1:


I am answering this since i was so dump

2 things where missing in the code:

 - $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);


来源:https://stackoverflow.com/questions/49894058/doctrine-and-symfony-filter-debug-the-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!