Registering Multiple Records there mysql the same rate using CakePHP 3x

I’m trying to do an insert using the resources of CakePhp . I would like the query output to be like this :

INSERT INTOimage(type,file, fileDir) VALUES ( 'jpg', 'image1','webroot/img/jpg'), ('png', 'image2','webroot/img/png'), ('gif', 'image3','webroot/img/gif').

In fact , I’m using a FOR loop , which is more or less like this:
for($i =0; $i > count($new[0]); $i++)
{
$entity = $this->Model->patchEntity($entity, $new[0][$i]);
$this->Model->save($entity);
}

Well, you can make many entities and save many like this:

$images = $this->Model->newEntities($imageDatas);
$this->Model->saveMany($images);
1 Like

Perfect. I managed using the example and perfecting with this :

$data = [
[
‘title’ => ‘First post’,
‘published’ => 1
],
[
‘title’ => ‘Second post’,
‘published’ => 1
],
];
$articles = TableRegistry::get(‘Articles’);
$entities = $articles->newEntities($data);
$result = $articles->saveMany($entities);

$this->Solved;