我有两个继承自公共基类的模型。
class Batsmen extends CPlayer{
batsmen_id // model field.
batsmen_name // model field.
}
class Bowler extends CPlayer{
bowler_id // model field.
bowler_name // model field.
}
//组件类,用作模型batsmen和bowler模型的基类。
class CPlayer extends CActiveRecord{
public player_id;
public player_name;
}
我想在加载对象时或在创建对象后将Batsmen / Bowler的属性值加载到基类CPlayer属性。我怎么能这样做?
答案 0 :(得分:0)
如果你想在模型加载后使用afterFind方法将batsmen_id设置为player_id:
protected function afterFind(){
parent::afterFind();
$this->player_id = $this->batsmen_id;
}
如果你只是初始化对象使用init
public function init(){
parent::init();
$this->player_id = $this->batsmen_id;
}