I have two tables of tables "user" and "role". I used the Yii 2.0 Gii framework to create a CRUD with the User model and the UserSearch model. By default, Gii uses GridView :: widget for the index page for the user model.
In the search method ($ params) inside the UserSearch model, I used the following code to combine the above tables together
$query = User::find()->with('role');
Everything works fine with the request.
By default, Gii does not include data from the joined 'role' table in the GridView :: widget inside the views / user / index.php page. With a join request, I was able to get data from both tables. On the page views / user / index.php, I introduced the GridView :: widget with the following code so that it also includes the data and column names from the joined table (role).
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'userid', 'username', 'role.role_name', ['class' => 'yii\grid\ActionColumn'], ], ]); ?>
Everything works fine with the role role_name included in the GridView :: widget. But the problem is that there is no search field for role_name. The GridView :: widget creates a search box only for user properties. Is there a way to add a search box for the properties of the related table role, because I would also like to search through the "role name", as well as through other properties of the user model.
source share