A
A
AlexAll2019-04-10 17:03:01
Yii
AlexAll, 2019-04-10 17:03:01

How to write from an array to different fields of a database table in yii2?

Hello, there is a multidimensional array
0 => {
date_from => "date",
date_to => "date",
price => "price",
}
1 => {
date_from => "date",
date_to => "date",
price => "price",
}
etc.
It is necessary to write to the database in which the fields date_from, date_to, price
thought that through foreache like this
foreach ($array as $key => $value){
$model = new Price;
$model->key = $value;
$model->save();
}
But so it turns out that at one iteration it is possible to write down only one field.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-04-10
@AlexAll

There are not only thoughts, there is a method in AR for this:
https://www.yiiframework.com/doc/guide/2.0/ru/db-a...
But you need to understand that there will be no validation and events like beforeSave etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question