Hi Chris,
I suppose you are dealing about multirecord form ? If yes, yes it's
quite simple.
Here are the different steps :
First, in a view, create a multi record display, with a loop on your
data and display input items for each record, like this :
echo $form->input('Mytable.'.$mytable['Mytable']['id'].'.myname',
array(
'label'=>''
,'value'=>$mytable['Mytable']['myname']
)
);
As you can see, each input item is unique, 'cause its ID is composed of
the unique id of the data.
It works fine with the paginator helper : just keep in mind that your
$data array is deeper !
This form will need an action to save multirecords :
<?php echo $form->create('Mytable',array('url'=>'/mytables/savemulti'));?>
About the controller :
one action to display the multirecord view :
function lists() {
$this->Mytable->recursive = 0;
$this->set('mytables', $this->paginate());
}
and the famous multirecord save :
function savemulti()
{
if (empty($this->data)) {
$this->Session->setFlash(__('Invalid Mytable', true));
$this->redirect(array('action'=>'lists'));
}
if (!empty($this->data)) {
if ($this->Mytable->saveAll($this->data['Mytable'])) {
$this->Session->setFlash(__('The Mytable has been
saved', true));
$this->redirect(array('action'=>'lists'));
} else {
$this->Session->setFlash(__('The Mytable could not be
saved. Please, try again.', true));
}
}
$this->redirect(array('action'=>'lists'));
}
The savemulti() is very similar to the standard edit method generated by
Bake for instance : I just call saveAll() instead of save() (be caution
: the parameters are differents).
That's all folks !
Chris Anderson a écrit :
> I have a page where I'm making changes to multiple instances of the
> same model (say, permissions for multiple users) on a page, but when I
> post it always ends up that $this->data only contains the information
> of the last entry posted. I'm assuming it simply is causing each
> subsequent "row" to overwrite the previous information in the array. I
> know how to handle form arrays in traditional php, but can Cake handle
> it appropriately so I would just have a nested array of each user I
> passed in the post? I asked in IRC and people seemed to think it was
> simple/possible, but no one could remember specifically what needed to
> be done. I didn't see anything about it in the form helper
> documentation, so presently I'm stumped.
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---