php – Yii Relations错误尝试获取非对象的属性

我有Cinema table&城市表和我通过id与这个表有关系.当我回显结果时,我有PHP通知“试图获取非对象的属性

问题是什么 ?还是我错过了什么?

我的代码
电影模型

public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'countryCode' => array(self::BELONGS_TO, 'TblCountry', 'country_code'),
        'city' => array(self::BELONGS_TO, 'TblCity', 'city_id'),
        'tblCinemaMovies' => array(self::HAS_MANY, 'TblCinemaMovies', 'cinema_id'),
        'tblDays' => array(self::HAS_MANY, 'TblDay', 'cinema_id'),
        'tblShowtimes' => array(self::HAS_MANY, 'TblShowtime', 'cinema_id'),
    );
}

城市模型

public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'tblCinemas' => array(self::HAS_MANY, 'TblCinema', 'city_id'),
        'countryCode' => array(self::BELONGS_TO, 'TblCountry', 'country_code'),
    );
}

查看文件

<?PHP echo $model->city_id->name; ?>

解决方法:

<?PHP echo $model->city->name; ?>

您必须使用$model-> city来获取$model的相应城市.

相关文章

1、将Yii2.0advanced版中应用主体frontend或backend应用复制...
Yii2restfulAPI文档一、配置模块:1.Config/main.php:  2...
Yii在framework/i18n/data/%lang%.php文件中有很多翻译.这...
在Yii2中,官方的页面多语言解决方案有两个:方案1,使用Yii...
Yii2.0对数据库查询的一些简单的操作1234567891011121314151...
数据查询User::find()->all();此方法返回所有数据;User:...