I struggle with the problem for a long time, but I still don’t understand how to solve it. There are 3 tables:

  • list of users of employees
  • a list of employee_positions posts (the external key id_user to the id of the employees table and the external key id_department to the id of the departments table) - each user has several posts from different departments
  • list of units

I do a query to the database like this:

$dataProvider = new SqlDataProvider([ 'sql' => ' SELECT * FROM `employees` e LEFT JOIN `employee_positions` p ON e.id=p.id_user LEFT JOIN `departments` d ON d.id=p.id_department ORDER BY e.fio ASC ', 'totalCount' => $count, ]); 

In the view I display the results, it turns out that each user is duplicated - how many posts he has so many lines. And I need each user to be once, but in the right column all his posts are listed and to which division this post belongs. Is it possible using GridView::widget ?

I tried to display a samopisnuyu table, but did not understand how to get the results from the provider $dataProvider ? var_dump($dataProvider) - does not contain the data itself.

    1 answer 1

    You can get current page data like this: $models = $dataProvider->getModels(); but it’s better to display everything with GrigView or ListView. less crap.

    It looks like your request gives such data. In this case, you need to look in the direction of the subquery in which the posts will be glued together by the concat and issued to the main query.

    In general, good create models for tables with bindings. and already in the GridView to get the associated post entries.