При сохранении формы (при заполнении полей только number и date_presc), остальные поля пустые, поля full_name, full_nameIssue, full_nameReceived и nameDepartment должны сохранятся со значением NULL(сохраняются с каким-то другим значением) и date(сохраняется 1970-01-01, а нужно сохранение текущей даты)
public function actionCreate()
{
$model = new WPrescription();
if ($model->load(Yii::$app->request->post())) {
$model->date = date('Y-m-d H:i:s',strtotime($model->date));
$empl = EmployeesBase::find()->where(['uuid'=>$model->nameIssue])->one();
if(!empty($empl))
{
$model->nameDepartment = $empl->nameDepartment;
}
$name = EmployeesBase::find()->where(['uuid'=>$model->name])->one();
if(!empty($name))
{
$model->full_name = $name->fullName;
}
$nameIssue = EmployeesBase::find()->where(['uuid'=>$model->nameIssue])->one();
if(!empty($nameIssue))
{
$model->full_nameIssue = $nameIssue->fullName;
}
$nameReceived = EmployeesBase::find()->where(['uuid'=>$model->nameReceived])->one();
if(!empty($nameReceived))
{
$model->full_nameReceived = $nameReceived->fullName;
}
$model->save();
/* WEvents */
$events = Yii::$app->request->post('events',[]);
$deadlines = Yii::$app->request->post('deadlines',[]);
$date = Yii::$app->request->post('date',[]);
foreach ($date as $num=>$value)
{
$new_record = new WEvents();
$new_record->id_prescription = $model->id;
$new_record->events = $events[$num];
$new_record->deadlines = $deadlines[$num];
$new_record->date = date('Y-m-d',strtotime($value));
$new_record->save();
}
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
]);
}