Okay. Thanks very much to John's help, I got this working with no more
problems. However, I have another need, related to this. I need to
perform autocomplete for each of the fields rendered from the foreach
loop. Now, using Firebug, I realize that each field rendered has the
same id, which will cause problems for the autocomplete. Here's my idea
and I would like to feedback to know if it's the best approach or not.
Since I'm rendering the field in a foreach loop, I decided to also use
an index field to set the id... something like this:
$i = 0
foreach ($fops as $fop => $foparray) {
echo $form->input('opcode', array('value' =>
$furnarray[opcode],'class' => 'short100r3', 'label' => false, 'div' =>
false, 'id' => 'FurnaceOpcode[' . $i . ']'));
}
The result is and an id's of "FurnaceOpcode[0]", "FurnaceOpcode[1]",
"FurnaceOpcode[2]", etc. My question is, do I simple process this as a
simple array on input in my controller? I need to apply some business
logic to each for adding/updating rows in a model. Will I be able to
simple process them as:
foreach ($fops as $fop) {
// some code
}
Thanks, Merrill
John Andersen wrote:
What is the structure of your array?
Take your array and pass it to the view using the controllers set
method. Example $this->set('myarray', $myarray);
In the view, write a foreach loop going through the myarray array.
Example:
[code]
foreach( $myarray as $rowNo => $arrayItem )
{
// Do your presentation here.
// $form->checkbox('myfield', array('value' => $arrayItem[xxx],
'label' => 'My label');
// $form->text('myfield2', array('value' => $arrayItem[yyy],
'label' => 'My text label');
}
[/code]
The above is just to get you started, so hope it helps :)
Enjoy,
John
On Jan 21, 7:52 pm, Merrill Kingston <[email protected]> wrote:
I had already read and tried that, but as explained in the docs...
"If you need to specify multiple fields using the same field name, thus
creating an array that can be saved in one shot with saveAll()..."
This is for displaying an array of rows from a table. This isn't exactly
what I need to do.
I need to load data into the controller, process it, and then display an
array of results from the processing. So, my need is to display the
contents of an array, created by the controller (not the model), one
member at a time. The documentation refers to displaying an array of
table rows from a model, as in the following example:
<?php
echo $form->input('Modelname.0.fieldname');
echo $form->input('Modelname.1.fieldname');
?>
I tried to treat it as a "group", but that didn't work either.
Using $this->set(compact('data','myarray') does add the array so the
view can display it, but if I attempt to loop through "myarray", I get
nothing. However, if I just do:
echo $form->input('myarray')
the data is rendered, but into a single field as a drop down list. I
need to be able to loop through the array and render each member
individually and I haven't been able to get any hints from the docs. For
example, I have tried:
for ($i = 0; $i < 42; $i++); {
echo $form->input('myarray[$i]')
}
My array gets rendered, but without any of the data.
[snip]
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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
--
Merrill Kingston
Phone: 702.798.1806
Fax: 702.522.1455
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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