CakePHP: Form Helper with saveMany () for editing multiple lines at once

In my opinion (/View/Tests/admin_edit.ctp) I want to edit some lines (from another model), pointing the form to QsetsController and the action "admin_order", then use saveMany($this->request->data)to update all the changes.

/View/Tests/admin_edit.ctp:

echo $this->Form->create( 'Qset', array('action'=>'order', 'admin'=>1));
$n = 1;
foreach ($qsets as $qset) : ?>
        <h3>Question set <?php echo $n; $n++;?></h3>
        <?php echo $this->Form->input('Qset.'.$n.'.order'); ?>
        <?php echo $this->Form->input('Qset.'.$n.'.id', array('type'=>'hidden') ); ?>
        ...
        $n++;

    endforeach;

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

/Controller/QsetsController.php

public function admin_order() {

    $data = $this->request->data; //maybe just $this->data ?

    $this->Qset->saveAll($data);
    $this->Session->setFlash( "Order saved.");
    $this->redirect( Controller::referer() );
}

Currently, my data is not saved (although there are no errors). In addition, only the first input appears, the echo of which is set by the foreach loop, with the correct field value order. Each subsequent one does not matter.

Update: I changed $n = 1to $n = 0, and now the first AND second input appears with their correct order values.

Update2: :

<form action="/admin/qsets/order" id="QsetOrderForm" method="post" accept-charset="utf-8">

, :

<div class="input number"><label for="Qset2Order">Order</label>
<input name="data[Qset][2][order]" type="number" value="3" id="Qset2Order">
</div>

, :

<div class="input number"><label for="Qset3Order">Order</label>
<input name="data[Qset][3][order]" type="number" id="Qset3Order">
</div>

Update3: ! , $n , . $n++ , . . .

:
saveMany()/saveAll()

+1
1

, , , :)

saveMany():

, $data . .

, $data $data['Qset'], All()/saveMany().

Controller::referer() $this->referer()

+3

All Articles