How to deactivate the update save() during the cycle
-
The code itself.
$model = new Image(); if ($model->load(Yii::$app->request->post())) { foreach($files->files as $file){ $years=date('Y'); $mounts=date('m'); $model->path = $path.'/'.$years.'/'.$mounts.'/'; $model->name = $files_to; $model->title_alt=$altNames." ".$count; $model->save(); $file->saveAs(Yii::getAlias('@frontend/web/image/') . $path . '/' . $years . '/' . $mounts . '/' . $files_to); } }
That's how it works in the de works.
INSERT INTO `fl_image` (`title_alt`, `for_home`, `id_film`, `path`, `name`) VALUES ('Тарзан. Легенда 0', 0, 1, 'film/2016/07/', '12089457.jpg') UPDATE `fl_image` SET `title_alt`='Тарзан. Легенда 1', `name`='Space-Desktop.jpg' WHERE `id`=2180 UPDATE `fl_image` SET `title_alt`='Тарзан. Легенда 2', `name`='xJtqzdQr7RE.jpg' WHERE `id`=2180
-
You should make a new facility. $model In a cycle like this:
foreach ($files->files as $file) { $model = new Image(); if ($model->load(Yii::$app->request->post())) { $years = date('Y'); $mounts = date('m'); $model->path = $path.'/'.$years.'/'.$mounts.'/'; $model->name = $files_to; $model->title_alt = $altNames." ".$count; $model->save(); $file->saveAs(Yii::getAlias('@frontend/web/image/') . $path . '/' . $years . '/' . $mounts . '/' . $files_to); } }