5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 714 Views |
-
onAfterWrite() Apache lost

8 March 2011 at 8:31am Last edited: 8 March 2011 8:33am
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
-
Re: onAfterWrite() Apache lost

9 March 2011 at 10:15pm
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.
-
Re: onAfterWrite() Apache lost

23 June 2011 at 4:05am
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();
} -
Re: onAfterWrite() Apache lost

15 July 2011 at 6:58am
I've done it a by using a plain jane sql query to do the write, that way its not using the write method
-
Re: onAfterWrite() Apache lost

15 July 2011 at 9:04am
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.
| 714 Views | ||
|
Page:
1
|
Go to Top |



