Answer the question
In order to leave comments, you need to log in
How to set yii 2 safe attributes?
I'm working with the basic version. I collect data from the form and want to write them to the database in bulk, through attributes. Here are my validation rules:
public function rules()
{
return [
[['name', 'date', 'parking_place', 'parking_time','spent_fuel', 'remain_fuel', 'distance'],
'required', 'message' => 'Поле не может быть пустым'],
[['parking_time','spent_fuel', 'remain_fuel', 'distance'],
'integer', 'message' => 'Значение должно быть целым числом'],
[['name', 'date', 'parking_place', 'parking_time','spent_fuel', 'remain_fuel', 'distance'],
'safe'],
];
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$fleet = new Fleet();
$fleet->setAttributes($model->attributes);
$fleet->save();
Yii::$app->session->setFlash('reportFormSubmitted');
return $this->refresh();
}
Answer the question
In order to leave comments, you need to log in
those. do you have two models in action? What is it for?
$model = new Fleet()
if (load, validate) {
$model->save();
// прочий код
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question