0

というテーブルがありますspecs。そこから複数の行を 1 つのフォームで編集し、一度に保存する必要があります。

// table structure
specs [id, name, value, owner_id]
// controller part
$data = $this->Spec->find('all'); // skipping the conditions and other sub-code
$data = set::combine(...);
/*
result, keyed using the spec[id] column.
array (
  [3] = array(id=>...),
  [22] = array(id=>...)
)
*/

今、私は続ける方法がわかりません。新しい複数のレコード (Model.{n}.fieldname) を作成する準備ができているフォームを作成する方法は知っていますが、「編集」フォームを作成するにはどうすればよいsaveAll()ですか?

結果配列を反復しようとすると、フォームが閉じます..しかし、入力要素のフィールドの値が表示されません..

4

1 に答える 1

0

これを試すことができます:

コントローラーで:

public function edit() {
    $products = $this->Product->find('all');
    if (!empty($this->data)) {
        if ($this->Product->saveAll($this->data['Product'])) {
            $this->Session->setFlash('ok');
        } else {
            $this->Session->setFlash('not ok');
        }
    } else {
        $this->data['Product'] = Set::extract($products, '{n}.Product');
    }
    $this->set(compact('products'));
}

ビューで:

echo $this->Session->flash();

echo $this->Form->create('Product');

foreach ($products as $i => $product) {
    echo $this->Form->input("$i.id");
    echo $this->Form->input("$i.name");
}

echo $this->Form->end('Save');

PS: 私のProduct例をあなたのニーズに合わせることができると思いますよね? : )

于 2012-04-09T20:47:36.280 に答える