Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

onAfterWrite() Apache lost


5 Posts   960 Views


8 March 2011 at 8:31am (Last edited: 8 March 2011 8:33am), Community Member, 180 Posts

i try to use onAfterWrite()


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;

return parent::onAfterWrite();




but when i save new rocord the Apache server get lost


9 March 2011 at 10:15pm Forum Moderator, 5511 Posts

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.


23 June 2011 at 4:05am Community Member, 11 Posts

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 );
      return parent::onAfterWrite();


15 July 2011 at 6:58am Community Member, 528 Posts

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


15 July 2011 at 9:04am Forum Moderator, 5511 Posts

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.