0
CakePHP
に複数のレコードを保存して配列内にリレーショナルデータ用のid
を含む配列要素を挿入しようとしています。配列の配列内に配列要素を挿入する最も良い方法
これは、配列がどのように表示されるかである:
[Venue] => Array (
[0] => Array (
[name] => Great mansion
[where] => New York
)
[1] => Array (
[name] => Diamond palace
[where] => London
)
[2] => Array (
[name] => Palazzo Falcone
[where] => Bologna
)
)
私は、配列の各要素にarchitect_id
を追加したい:
[Venue] => Array (
[0] => Array (
[name] => Great mansion
[where] => New York
[architect_id] => 33
)
[1] => Array (
[name] => Diamond palace
[where] => London
[architect_id] => 33
)
[2] => Array (
[name] => Palazzo Falcone
[where] => Bologna
[architect_id] => 33
)
)
私はわからないんだけど、私は「何場合書いたVEのは、最適化されているか、それを向上させることができます。
$tot = count($this->request->data['Venue']);
for ($i = 0; $i < $tot; $i ++) {
$this->request->data['Venue'][$i]['architect_id'] = $this->Architect->id;
}
$this->Venue->saveAll($this->request->data['Venue']);
コードは動作しますが、これはそれを行うには良い方法ですか?
私はこのソリューションを選択しました。ありがとうございます。 – vitto