开发者

copy/archive object in database - Symfony

开发者 https://www.devze.com 2023-04-01 20:29 出处:网络
i would like make copy if i add and edit News. class News extends BaseNews { public function postSave(){

i would like make copy if i add and edit News.

class News extends BaseNews
{
    public function postSave(){

        $copy = new CopyNews($this);
        $copy->save();
    }

    public function save(Doctrine_Connection $conn = null)
    {
      return parent::save($conn);  
    }
}

but i h开发者_开发问答ave error:

Strict Standards: Declaration of News::postSave() should be compatible with that of Doctrine_Record::postSave() in ...

How can i make this?


All pre- and post- methods receive $event as a parameter. You should rewrite the method as

 public function postSave(Doctrine_Event $event){
    $copy = new CopyNews($event->getInvoker());
    $copy->save();
 }


All you need is within doctrine

$copy = $this->copy()

... and it's documentation :

http://www.doctrine-project.org/documentation/manual/1_2/en/component-overview:record:getting-object-copy

0

精彩评论

暂无评论...
验证码 换一张
取 消