2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【CakePHP】Model::Create()

Last updated at Posted at 2015-10-13

Model::save()の前に実行するcreate()についてもろもろ。

前のsave()の残りをクリアしてくれる。

→ループの中でsave()繰り返すときは忘れずcreate()する件。

DBのデフォルト値を設定してくれる。

デフォルト値いらないなー、クリアだけしてくれればいいのにってときは、nullもしくはfalseをパラメータで渡す。

モデルの初期化を行うことができる。

→あまり利用シーン思いつかないなー。POSTとデフォルト値マージする場合とか?自分ならarray_merge()使いたいかも。

$this->User->create([
  'name'=>'suzuki'
]);

$this->User->save([
  'weight'=>60
]);
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?