我的背景是 Propel,所以我希望在 Doctrine_Record (sfDoctrineRecord) 中覆盖一个神奇的 getter 是一件简单的事情,但是我得到了一个 Segfault 或者覆盖方法被简单地忽略了超类中的一个.
My background is in Propel, so I was hoping it would be a simple thing to override a magical getter in a Doctrine_Record (sfDoctrineRecord), but I'm getting either a Segfault or the override method is simply ignored in favor of the one in the superclass.
https://gist.github.com/697008eaf4d7b606286a
class FaqCategory extends BaseFaqCategory
{
public function __toString()
{
return $this->getCategory();
}
// doesn't work
// override getDisplayName to fall back to category name if getDisplayName doesn't exist
public function getDisplayName() {
// also tried parent::getDisplayName() but got segfault(!)
if(isset($this->display_name)) {
$display_name = $this->display_name;
} else {
$display_name = $this->category;
}
return $display_name;
}
}
在 Doctrine_Record 实例上扩展/覆盖方法的正确 Doctrine 方法是什么(通过 sfDoctrineRecord 扩展 Doctrine_Record)?这必须是可行的...还是我应该查看模板文档?
What is the proper Doctrine way to extend/override methods on an instance of Doctrine_Record (via sfDoctrineRecord extends Doctrine_Record)? This has to be doable...or should I be looking at the Template documentation?
谢谢,布赖恩
试试 _get 和 _set 方法.
Try _get and _set methods.
这篇关于在 Doctrine PHP Symfony 中覆盖 Doctrine_Record (sfDoctrineRecord) 实例方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!