How to get specific field that related with id

I have 2 database that includes countries the other one includes cities. When I want to add new city. I can see the countries that in dropdown menu that I added. However, When I want to list city and the country it belongs to, I can see the id of the country instead of country name.How can I see the name of country in the list. this is my controller:

 public function actionIndex()
{
    $this->view->title = 'Şehirler';
    $countries= ArrayHelper::map(AdrCountry::find()->all(),'id','name');

    $cities = AdrCity::find()->all();

    return $this->render('index', [
        'cities' => $cities,
        'countries' => $countries

    ]);
}

This the view file(imdex.php)

 <?php foreach ($cities as $city): ?>
                        <tr>
                            <td><input type="checkbox" name="delete[]" value="<?= $city->id?>"></td>
                            <td><a href="<?= Url::to(['city/update', 'id' => $city->id]) ?>"><?= $city->name ?></a></td>
                            <td><?= $city->adr_country_id ?></td>
                                   </tr>
                             <?php endforeach; ?>

https://forum.yiiframework.com/search?q=%23yii-2-0%20dependent%20dropdown

I have the get function in my AdrCity.php model.Still I get the id not the name

 public function getAdrCountry()
{
    return $this->hasOne(AdrCountry::className(), ['id' => 'adr_country_id']);
}

Note: While adding the new city I can see tha name of the country. However, When I want to see all cities with their country name. I am not able to see the country name. I have problem with listing

You need to use relationName.columnName to display column from related table.

<td><?= $city->adrCountry->name ?></td>
1 Like

Thanks a lot