Jump to:

5512 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » onAfterWrite() Apache lost

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 931 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    onAfterWrite() Apache lost Link to this post

    i try to use onAfterWrite()

    <?php

    class ProduktKolory extends DataObject {

    static $db = array(
    'Nazwa' => 'Varchar',
    'URL' => 'Varchar'
    );
    static $has_one = array(
    'Produkt' => 'Produkt',
    'Kolor' => 'ModulKolory'
    );

    public function getCMSFields_forPopup() {

    $source_kolory = DataObject::get('ModulKolory');
    $kolory = $source_kolory->toDropDownMap('IkonaID','Nazwa');

    return new FieldSet(
    new DropdownField('KolorID','Wybierz kolor:',$kolory)
    );
    }

    public function onAfterWrite() {

    $filter = "IkonaID = $this->KolorID";
    $kolor = DataObject::get_one('ModulKolory',$filter);

    $filter = "ID = $this->KolorID";
    $file = DataObject::get_one('File',$filter);

    $filter = "ID = $this->ID";
    $produkt_kolor = DataObject::get_one('ProduktKolory',$filter);
    $produkt_kolor->Nazwa = $kolor->Nazwa;

    $produkt_kolor->URL = $file->Filename;
    $produkt_kolor->write();

    return parent::onAfterWrite();

    }

    }

    ?>

    but when i save new rocord the Apache server get lost

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: onAfterWrite() Apache lost Link to this post

    Creating a ProduktKolory inside the onAfterWrite() will trigger another onAfterWrite(), it's probably stuck in a horrible loop thanks to $produkt_kolor = DataObject::get_one('ProduktKolory',$filter); always firing.

  • WebInt
    Avatar
    Community Member
    11 Posts

    Re: onAfterWrite() Apache lost Link to this post

    Can anyone think of a workaround for that?

    Perhaps a writeWithoutEvent() function would be the remedy?

    Anyway, really need to figure out how to get around this pronto!

    function onAfterWrite() {
          $fields = $this->getField($this->dbObject("Region1"));
          $this->setField("Regions", $fields );
          $this->write();
          return parent::onAfterWrite();
    }   

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: onAfterWrite() Apache lost Link to this post

    I've done it a by using a plain jane sql query to do the write, that way its not using the write method

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: onAfterWrite() Apache lost Link to this post

    Well if you set the field, never call write the field *should* still get saved as the write is executed after that function is run.

    931 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.