LoginSignup
1
0

More than 5 years have passed since last update.

CakePHP3でEntityを新規保存する方法

Last updated at Posted at 2018-08-01

Entityを保存する場合、1レコード作成する方法と複数レコード作成する方法が違うため、メモ

バージョン

CakePHP 3.5
PHP 7.2

新規保存

1レコード作成する方法

UsersController.php
public function add()
{
    if ($this->request->is('post') {
        $entity = $this->newEntity($this->request->getData());
        $this->save($entity);
    }
}

複数レコード作成する方法

UsersController.php
public function add()
{
    if ($this->request->is('post') {
        $entities = $this->newEntities($this->request->getData());
        $this->saveMany($entities);
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0