-->

Doctrine2 - is there a pre-selection hook?

2019-08-05 16:47发布

问题:

I'm developing a ws with Symfony2 / Doctrine2, and I'm trying to hook into Doctrine2 lifecycle and trigger a function before any SELECT action - but without any luck. Basically, i'd like to dynamically manipulate the selection queries adding limit/offset when certain parameters are found in the request, but it seems that Doctrine2 hooks concern only insert, delete and update actions. Am i missing something?

Thanks.

回答1:

U have to use Doctrine Filter

Doctrine 2.2 features a filter system that allows the developer to add SQL to the conditional clauses of queries, regardless the place where the SQL is generated (e.g. from a DQL query, or by loading associated entities).



回答2:

A way to deal with this would be to register a custom event that is dispatched before a select. You have already referenced the source that shows examples of how to do it.