基于Idiorm的 PHP orm Granada通过以下方式从数据库中检索字段:
class ORM {
...
public function __get($key) {
return $this->get($key);
}
}
class ORMWrapper extends ORM {
...
public function get($key) {
if (method_exists($this, 'get_' . $key)) {
return $this->{'get_' . $key}();
} elseif (array_key_exists($key, $this->_data)) {
return $this->_data[$key];
}
elseif (array_key_exists($key, $this->ignore)) {
return $this->ignore[$key];
}
// and so on ...
}
我的问题是,如果我public $field
在我的模型类中定义,魔术方法 __get 不会被调用,所以 ORM 不会从数据库中检索字段?
我怎样才能
- 能够
public $field
在我的模型类中声明 $field
如果未定义,仍然调用魔法吸气剂
同时?