【发布时间】:2012-03-25 01:28:47
【问题描述】:
我有 Cinema 表和 City 表,我通过 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; ?>
【问题讨论】:
-
您在哪里创建
model和city_id?你确定它们存在吗? -
不,我没有我认为 $model->city_id->name;是 fase 但这是工作 $model->city_id;结果 = 身份证号码.. :( 我怎样才能得到“名字”?