Thanks a lot, I have a rought idea of what i need to do. I presume from
this that I can't use the html checkbox helper to generate the checkbox
ids?

On Jan 2, 2:02 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
I haven't done multi-row edit forms in Cake, but I've done them in
ordinary PHP procedural code. What you have to do is create a form
which displays all the rows you want to see at one time, with <input>
fields for the values you want to be editable. This is much like the
ordinary list view generated by bake, but with some of the output
values replaced by input fields.

The PHP code for all this turns out to be somewhat tedious. I'd love to
have bake generate it all for me!

Anyway, what follows would typically be generated by your PHP code, but
for these examples I am just supplying the html. I would appreciate any
corrections to the inevitable mistakes I will now proceed to make.

Take a look at the organization of an ordinary single-value Edit form
and its controller function, as generated by bake. Our multi-row
controller will be a variant of that concept. For a single-row zipcode
entry form for the customers table, we might have this:

<form>
Enter your Zipcode: <input type="text" name="zipcode">
<input type="submit" name="OK">
</form>

PHP passes the input value $zipcode to the controller as part of the
$_POST array, but the Cake library helps even more by and arranging the
data so that the controller just has to do this:

if($this->Customer->save($this->data)) {
  $this->Session->setFlash('Your new customer information has been
saved');

}But to input three rows of zipcodes, going back to the form, we would
have this:

<form>
Mr. Smith's Zipcode: <input type="text" name="zipcode[0]"><br>
Ms. Parta's Zipcode: <input type="text" name="zipcode[1]"><br>
Mr. Archer's Zipcode: <input type="text" name="zipcode[2]"><br>
</form>

In a multi-row controller, instead of saving one zipcode value in one
database row, we have to save three zipcode values in three database
rows. That means calling save() three times with three different
primary keys of the customers table.

Therefore we should pass those primary keys in corresponding array
positions, so that the controller will know in which row to store each
value. Suppose that the primary keys for customers Smith, Parta and
Archer are 1017, 1035, and 1050.

<form>
<input type="hidden" name="id[0]" value="1017">
Mr. Smith's Zipcode: <input type="text" name="zipcode[0]">
<br>
<input type="hidden" name="id[1]" value="1035">
Ms. Parta's Zipcode: <input type="text" name="zipcode[1]">
<br>
<input type="hidden" name="id[2]" value="1050">
Mr. Archer's Zipcode: <input type="text" name="zipcode[2]">
</form>

I know it looks peculiar to have a field called, say, "zipcode[1]" or
"id[2]", but PHP is smart and will use those names to create an array
$zipcode and an array $id, containing the entered values, in the
correct array locations.

After the user clicks OK, PHP hands your controller the $zipcode[]
array and the $id[] array as part of the $_POST[] array. Your
controller code then has to save each zipcode value from the $zipcode[]
array into the database row specified by the $id[] array. For example,
the value entered for $zipcode[2] goes with the database row whose id
is $id[2], that is, 1035.

So your multi-row controller can't just have this:

$this->Customer->save($this->data)

Instead the controller has to do three separate saves, with the data
prepared correctly for each save. I won't try to write the controller
code here, but I hope the above gives the basic idea of how to make it
work. Probably there is a way to combine all the rows of the id[] and
zipcode[] arrays, and then just call save() one time, but I don't know
how to do it.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to