Symfony - Doctrine - How to save SQL query to Session

If you have separated ajax table sheet with data and filters, sometimes, you need to keep this filtered data between requests.

In my case, I needed to be able to download file in CSV format, after choosing all necessary filters in table.

So, it is possible to store SQL query in client Session after applying all filters and receive data from DB via DQL.

To store DQL in session:

$query = $this->createQueryBuilder('i')->select('COUNT(i)');
$_SESSION['query'] = $query->getQuery()->getDQL();
$_SESSION['query_params'] = $query->getQuery()->getParameters();

To get data from DB:

$data = $this->createQuery($_SESSION['query'])->setParameters($_SESSION['query_params'])->getResult();

Comments

Popular posts from this blog

Idea PhpStorm - How to fix bugs with incorrect code Inspections and Autocomplete

Symfony - Twig - How to check on instanceof class object

CSS Как прикрепить слой (div) к краю