在Doctrine PHP Symfony中覆盖Doctrine_Record(sfDoctrineRecord)实例方法 [英] Overriding Doctrine_Record (sfDoctrineRecord) instance methods in Doctrine PHP Symfony
问题描述
https://gist.github .com / 697008eaf4d7b606286a
class FaqCategory extends BaseFaqCategory
{
public函数__toString()
{
return $ this-> getCategory();
}
//不工作
//如果getDisplayName不存在,则覆盖getDisplayName返回到类别名称
public function getDisplayName(){
//也尝试了parent :: getDisplayName()但是得到了segfault(!)
if(isset($ this-> display_name)){
$ display_name = $ this- > DISPLAY_NAME;
} else {
$ display_name = $ this-> category;
}
return $ display_name;
}
}
适当的Doctrine方式来扩展/覆盖Doctrine_Record实例(通过sfDoctrineRecord扩展Doctrine_Record)的方法?这必须是可行的,或者我应该看模板文档?
谢谢,
Brian
尝试_get和_set方法。
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;
}
}
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?
Thanks, Brian
Try _get and _set methods.
这篇关于在Doctrine PHP Symfony中覆盖Doctrine_Record(sfDoctrineRecord)实例方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!