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

Which PHP Framework to choose in 2024

jQuery UI - Dialog - How to hide autofocus

HTML - How to add placeholder to dropdown (select) with selectpicker