有关在 Kohana ORM 中声明模型的一些问题
所以我刚刚开始学习使用 ORM,当我第一次开始学习 Ko3 时就使用 Jelly,并遇到了一些问题......它们可能看起来很愚蠢,所以请耐心等待。
首先,我注意到声明模型足以开始使用它,而无需分解字段。这是我不知道的自动魔法吗?如果是这样......它会导致性能问题吗?应该避免吗?
我还注意到声明规则的两种不同方式......这两种方法有什么区别?
public function rules() {
return array(
'categoryname' => array(
array('not_empty'),
),
);
}
protected $_rules = array(
'categoryname' => array(
'not_empty' => true,
),
);
So I just started learning to use ORM, went with Jelly when I first started learning Ko3, and have run into a few questions... they may seem stupid so please bear with me.
First I noticed that declaring the Model is enough to start using it, without having to break down the fields. Is this some automagic I'm unaware of? If so... does it cause performance issues and should it be avoided?
I've also noticed two different ways of declaring rules... what's the difference between these two methods?
public function rules() {
return array(
'categoryname' => array(
array('not_empty'),
),
);
}
protected $_rules = array(
'categoryname' => array(
'not_empty' => true,
),
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SHOW COLUMNS
。但您可以简单地缓存它。rules()
已在 Kohana 3.1 中添加(3.0 使用$_rules
属性)。现在您可以在返回规则列表之前应用一些逻辑。并且它更适合模型扩展,例如:SHOW COLUMNS
on empty model. But you can simply cache it.rules()
was added in Kohana 3.1 (3.0 uses$_rules
property). Now you can apply some logic before return rule list. And its better for model extending, for example: