I am certain this is just a silly mistake somewhere in my code but onBeforeSave() doesn’t seem to be working as I expect.
I basically have this:
public function onBeforeSave(){
if($this->isNewRecord){
$this->ordertime = time();
$this->status = 1;
}
}
I however get an error saying that the status field is empty. I am just trying to set them when a record is inserted for the first time. Am I missing something?
Do you get the error because you have a ‘required’ validation rule? If so you may want to use beforeValidate() instead (or you can inhibit exclude validation by using a scenario).