A
A
Albert Tobacco2015-01-27 16:14:27
Yii
Albert Tobacco, 2015-01-27 16:14:27

How to use Yii 2 GRID widget with two tables?

I have two tables `user` and `auth_assignment` (which store user roles).
GIi generator to do CRUD for table `user`.
The question is how do I bind the auth_assignment table to it?
I found one way
(the code that was)

$query = UserList::find();

$dataProvider = new ActiveDataProvider([
            'query' => $query,
 ]);

Here is the way I did it
$query = (new \yii\db\ActiveQuery())
            ->select( ['id' => 'user.id', 'username' => 'user.username' , 'auth_assignment.item_name' ])
            ->from('user')
            ->leftJoin('auth_assignment', 'auth_assignment.user_id = user.id');

 
$dataProvider = new ActiveDataProvider([
        'query' => $query,
]);

B, everything would be fine, but with such a formation of $dataProvider, the grid does not work fully, sorting does not work, and the search does not work either.
Where to move where to look?
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2015-01-27
@bighoc

Read about relations
www.ramirezcobos.com/2014/04/16/displaying-sorting...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question