Help us understand the problem. What is going on with this article?

CakePHP 複数レコードを一括保存するsaveAllの使い方

ビュー

form.ctp
echo $this->Form->create ( 'User', array (
    'type' => 'post',//POSTとGETの設定
    'controller' => 'users',//コントローラーの設定
    'action' => 'edit',//アクションの設定
) );

echo $this->Form->input ( 'User.0.name.');
echo $this->Form->input ( 'User.0.age');

echo $this->Form->input ( 'User.1.name');
echo $this->Form->input ( 'User.1.age');


echo $this->Form->input ( 'User.2.name');
echo $this->Form->input ( 'User.2.age');

echo $this->Form->end('送信');

$this->request->data;の中身

$data = array(
    'User' => array(
        0 => array(
            'name' => '太郎',
            'age' => 10
        ),
        1 => array(
            'name' => '花子',
            'age' => 8
        ),
        2 => array(
            'name' => '二郎',
            'age' => 5
        ),
    )
);

$data["User"]というように$dataの後ろにモデル名を指定するところがポイントです。

$this->User->saveAll($data["User"]);
joruju2248
大阪でweb系自社開発の会社で働いてます。
https://sho-programming.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away