0

I'm following this tuto about CSV export on EasyAdmin bundle in symfony (link) and I'm stuck at this point:

$queryBuilder = $this->createListQueryBuilder(

        Employee::class,
        $sortDirection,
        $this->request->query->get('sortField'),
        $this->entity['list']['dql_filter']
    );
        return $this->csvExporter->getResponseFromQueryBuilder(
        $queryBuilder,
        Employee::class,
        'employees.csv'
    );

UPDATE: I'm overwriting the method createListQueryBuilder

protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null   , $dqlFilter = null){}

and in the csvExporter i'm defining a function getResponseFormQueryBuilder

public function getResponseFromQueryBuilder(QueryBuilder $queryBuilder, $columns, $filename)

I'm having a bug that says that:

Expected parameter of type '\Doctrine\ORM\QueryBuilder', 'void' provided

  • Show the whole function please. Your calling a function which has a parameter requirement of `QueryBuilder $queryBuilder` and your providing something with value `void`. – rkeet Feb 20 '20 at 07:47
  • check the update please @rkeet – Khaoula Arfaoui Feb 20 '20 at 08:49
  • Hmm yes, well, if you use Xdebug you'd see that `$queryBuilder === null` evaluates to true probably. The function `$this->createListQueryBuilder(...)` is not returning what you expect. As such the subsequent `*->getResponseFromQueryBuilder(...)` call fails on a non-received value. – rkeet Feb 20 '20 at 09:09
  • what should i do (sorry i'm a beginner) – Khaoula Arfaoui Feb 20 '20 at 09:16
  • Follow the instructions for [installation of Xdebug](https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html) (check your needed version [here](https://xdebug.org/wizard)), then set breakpoints in your code and step through line by line to see what's not working correctly ;-) If you want to take the manual route, set and declare each variable outside of the function call separately and `var_dump` (or how you like to do it) to the front-end to check values. So: `$class = Employee::class` then use `$this->createListQueryBuilder($class, ...)` (example) - xdebug = better though - faster – rkeet Feb 20 '20 at 09:35
  • the bug is when i override the function createListQueryBuilder – Khaoula Arfaoui Feb 20 '20 at 10:03
  • i define an empty funtion [ protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null , $dqlFilter = null){} ] and then i populate in another class is this wrong ? – Khaoula Arfaoui Feb 20 '20 at 10:05

2 Answers2

0

i was overwriting the wrong funtion you should define it like this (before you overwrite it)

protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
/**
 * Performs a database query based on the search query provided by the user.
 * It supports pagination and field sorting.
 *
 * @param string      $entityClass
 * @param string      $searchQuery
 * @param array       $searchableFields
 * @param int         $page
 * @param int         $maxPerPage
 * @param string|null $sortField
 * @param string|null $sortDirection
 * @param string|null $dqlFilter
 *
 * @return Pagerfanta The paginated query results
 */    {
    return $this->get('easyadmin.query_builder')->createListQueryBuilder($this->entity, $sortField, $sortDirection, $dqlFilter);
}
-1

you should make sure $queryBuilder is type of QueryBuilder , I advise you to trace debug $queryBuilder variable before return line and detect why it's void.

Khaled Alam
  • 885
  • 7
  • 12