如何在不破坏ORM功能的情况下使用idiorm/granada定义模型字段? [英] How to define model fields with idiorm/granada without breaking the ORM functionality?
本文介绍了如何在不破坏ORM功能的情况下使用idiorm/granada定义模型字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基于
The PHP orm Granada based on Idiorm works the following way to retrieve fields from database:
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不会从数据库中检索字段?
My problem is that if I define public $field
in my model classes, the magic method __get is not called, and so the ORM does not retrieve the field from the database?
我怎么
- 能够在我的模型类中声明
public $field
- 如果
$field
未定义,仍然调用魔术吸气剂
- Be able to declare
public $field
in my model classes - Still call the magic getter if
$field
is undefined
同时?
推荐答案
我真正想做的就是让自动完成功能在netbeans上运行.
All I actually wanted to do is the have the autocompletion working on netbeans.
像这样声明我的Model类即可完成工作:
Just declaring my Model classes like that did the job:
/**
* @property int $address_id
* @property Address $address
* @property String $name
* ...
*/
class Activity extends Model {
public function address() {
return $this->belongs_to('Address');
}
//...
}
我可以这样做
$activity->address->name;
我完成了工作,ORM都在工作.
And I have the completion and the ORM both working.
这篇关于如何在不破坏ORM功能的情况下使用idiorm/granada定义模型字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文