On Sat, Feb 19, 2011 at 6:54 PM, Thomas <[email protected]> wrote:
> Basically if I remove the $i from the input in cake it renders all the
> inputs the same name, or key if you will, I do not need to get rid of
> the loop. I do not know the length of the loop as it is variable. I
> will attach again what I have with cake and a snippet from a regular
> php project that show what I need to do.
>
> This is cake->
> echo $form->checkbox('OnsiteTrainingClass.select_class'.
> $i,array('id'=>'select'.$i,'label'=>'','value'=>
> $value['OnsiteTrainingClass']['id']));
> echo $form->text('OnsiteTrainingClass.seats'.
> $classid,array('id'=>'select'.
> $i,'label'=>'','value'=>'1','size'=>'2'));
It looks to me like the loop is something like this:
foreach ($values as $i => $value)
{
echo $form->checkbox(
'OnsiteTrainingClass.select_class'.$i,
array(
'id'=>'select'.$i,
'label'=>'',
'value'=> $value['OnsiteTrainingClass']['id']
)
);
}
Although, why the label is empty is another thing.
If the association is HABTM, you could probably get what you're after by doing:
$this->set(
'classes',
$this->YourModel->OnsiteTrainingClass->find('list')
);
echo $form->select(
'OnsiteTrainingClass.OnsiteTrainingClass',
$classes,
null,
array('multiple' => 'checkbox')
);
No, I don't know why the model name must be repeated.
Another situation is where you've got an unknown number of hasMany
items. For a Poll plugin I wrote, the form starts out with 4 empty
PollOption elements, and some JS allows for adding more or removing
some elemnts. This is the naming format used:
<?= $this->Form->input('PollOption.0.title', array('label' => false,
'class' => 'PollOption')) ?>
<?= $this->Form->input('PollOption.1.title', array('label' => false,
'class' => 'PollOption')) ?>
<?= $this->Form->input('PollOption.2.title', array('label' => false,
'class' => 'PollOption')) ?>
<?= $this->Form->input('PollOption.3.title', array('label' => false,
'class' => 'PollOption')) ?>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php