3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1965 Views |
-
onBeforeWrite() not working properly

17 December 2009 at 11:39pm
Hi,
i have a problem with the onBeforeWrite hook.
I want to give a customer DataObject a special customer-number (Kundennummer in german) on the first write.
Here is the code:function onBeforeWrite() {
/* new Customer -> generate Customer# */
if(!$this->ID) {
$this->Kundennummer = Kundennummer::createKundennummer($_POST["PLZ"]);
echo $this->Kundennummer; //56073001 <- correct
}parent::onBeforeWrite();
}But the result is, that the customer gets the default value (=0) as his customer-number.
Any ideas about this?Greetings
Michael -
Re: onBeforeWrite() not working properly

18 December 2009 at 3:13am
Hi Michael
Try to move the parent::onBeforeWrite() to the beginning of your function
-
Re: onBeforeWrite() not working properly

18 December 2009 at 11:42pm
Same thing, customer id is set to default value.
-
Re: onBeforeWrite() not working properly

19 December 2009 at 1:14am
It should work. Can you post your class-code please? Or better: Put it on http://pastie.org/
-
Re: onBeforeWrite() not working properly

19 December 2009 at 2:00am
This is my complete customer class:
http://pastie.org/private/hbmrjsytxyatbyqv84upxqKundennummer::createKundennummer is working like expected.
-
Re: onBeforeWrite() not working properly

19 December 2009 at 3:01am
I gave this a try.
Seems like you can't use $this->ID to check if it's a new Record. This worked for me:function onBeforeWrite() {
parent::onBeforeWrite();
if(!$this->Kundennummer) {
$this->Kundennummer = Kundennummer::createKundennummer($_POST["PLZ"]);
}
} -
Re: onBeforeWrite() not working properly

19 December 2009 at 3:54am
Thanks, that's working.
I'm wondering because the
output appeared...echo $this->Kundennummer;
Chase for the X-Files
Greetings
| 1965 Views | ||
|
Page:
1
|
Go to Top |


