Page::saveIf($field)
Version 3.8
Save data to database, if field has a value.
Version 3.8
Save data to database, if field has a value.
Save data only if given field has a valid value according to Field::hasValue() -method.
$this
Save page, if amount has a value.
$this->get('page','order')
->setValue('customer',$customer->getId())
->setValue('amount' ,$amount)
->saveIf('amount');
This is shorthand for:
$Order = $this->get('page','order')
->setValue('customer',$customer->getId())
->setValue('amount' ,$amount);
if ( $Order->amount->hasValue() ){
$Order->save();
}
Save changes if user is office worker:
$isOffice = $this->get('user')->isProfile('office') ? true : false ;
$Order->saveIf($isOffice);