【发布时间】:2014-06-25 09:15:35
【问题描述】:
我有 ORM 模型硬件。并且硬件与 Type ORM 模型有关。 我需要从硬件模型中获取选项,例如:
$hardware->option
但如果选项为空,我想从类型模型中获取选项:
$hardware->type->option
我想以硬件形式自动(透明)进行。我做到了:
public function __get($column) {
if($column == 'option') {
if ($this->option != null) {
return $this->option;
} else {
// if option equals null then use value from type of this hardware
return $this->type->captive_portal;
}
}
return parent::__get($column);
}
但它不起作用。因为 $this->option 不起作用,因为首先我需要调用父 __get 方法来进行关系工作。但我不能调用父方法 __get 并在它获得真正的价值之后。还是可以?
【问题讨论】: