There are three tables in the database associated with foreign keys.

-- `country` `id` `name` -- `region` `id` `name` `country_id` -- `city` `id` `name` `region_id` 

Using the generator, Gii generated code for the city table. With the help of GridView derived the following data from the fields: Name of the Region, Name of the City, but I cannot understand how to display the name of the Country.

How to display so that all the names (Country, Region, City) were in the same table using the Gridview ?

  • In general, using gridview tools is it possible to implement this - Xfirab
  • Does anyone have any ideas? - Xfirab

1 answer 1

If you have configured the connection, you can:

 <?= GridView::widget([ //... 'columns' => [ 'region.country.name:text:Страна', 'region.name:text:Регион', 'name:text:Город', ], ]) ?> 
  • and how for the Страна field to add search fields to the same Gridview ? - Xfirab
  • In principle, it works, but a lot of queries to the database are obtained, is it possible to optimize it somehow? - Xfirab
  • Read about the greedy download . - KiTE
  • read so far is not very clear - Xfirab