Janlon
August 1, 2016, 9:19pm
1
I’m trying to do an insert using the resources of CakePhp . I would like the query output to be like this :
INSERT INTO
image(
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);
}
Tao
August 2, 2016, 6:21am
2
Well, you can make many entities and save many like this:
$images = $this->Model->newEntities($imageDatas);
$this->Model->saveMany($images);
1 Like
Janlon
August 2, 2016, 9:13pm
3
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;