Symfony中覆盖Doctrine

Symfony中覆盖Doctrine

本文介绍了在Doctrine PHP Symfony中覆盖Doctrine_Record(sfDoctrineRecord)实例方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的背景是在Propel,所以我希望在Doctrine_Record(sfDoctrineRecord)中覆盖一个魔法吸气剂是一件简单的事情,但是我得到了一个Segfault或者是覆盖方法是被忽略的,有利于一个超类。



  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)实例方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:39