[英]Phalcon PHP: getter/setter syntax for ->save()/->update()/->create()
I'm a little bit confused after reading the documentation. 阅读文档后,我有些困惑。 It mentions that ->save()/->create()/->update() all will implicitly reference getters and setters for model properties if they exist.
它提到-> save()/-> create()/-> update()都将隐式引用模型属性的getter和setter(如果存在)。 What's the syntax for this sort of thing?
这种事情的语法是什么? Specifically, what do I do when a property is related to a field in my table with underscores in it's name?
具体来说,当属性与表中带有下划线的字段相关时,该怎么办? An example of what I think should work:
我认为应该起作用的一个示例:
class Events extends \Phalcon\Mvc\Model {
protected $id;
protected $event_name;
public function setEventName($name){
$this->event_name = $name;
}
}
Maybe not a direct answer: 也许不是直接的答案:
For changing column names you can better use: Column mapping then you would not worry about setters/getters. 要更改列名,您可以更好地使用: 列映射,这样您就不必担心setter / getters了。
Besides that AFAIK Phalcon uses magic getters/setters for fields, so if you have $id
it will use magic getter for $id
or use a $eventsObj->getId()
if that method explicitly exist in class. 除此之外AFAIK尔康使用的魔法领域的getter / setter方法,所以如果你有
$id
会使用魔法的getter为$id
或使用$eventsObj->getId()
如果该方法在课堂上明确地存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.