0

I'm very new to CakePHP (and only slightly less new to MVC concepts) and am trying to build a system with a HABTM relationship between events and participants. I'd like the index page to display a list of events in a table, with one cell of each row containing a full list of participants. So far, my table display loop code looks like:

<?php foreach ($events as $event): ?>
<tr>
    <td><?php echo $event['Event']['id']; ?></td>
    <td><?php echo $event['Event']['title']; ?></td>
    <td><?php       
            foreach ($participants as $participant):
                echo $participant['Participant']['name'];
            endforeach;
        ?></td>
</tr>
<?php endforeach; ?>

I know this is wrong, but I've tried many variations on this theme (all of which seem to my mind as equally wrong), such as $event['Participant']... and nothing works. I know the answer is simple, but I don't know what it is and searching around just gives answers to similar, but not sufficiently similar, answers. What do I need to write?

rbobbington
  • 123
  • 6

1 Answers1

0

I would do something like this considering recursive IS NOT 0 in your controller.

<?php foreach ($events as $event): ?>
<tr>
    <td><?php echo $event['Event']['id']; ?></td>
    <td><?php echo $event['Event']['title']; ?></td>
    <td><?php       
        foreach ($event['Participant'] as $participant):
            echo $participant['name'];
        endforeach;
    ?></td>
</tr>
<?php endforeach; ?>

This is untested. So if you need anymore help on this solution, please let me know.

AKKAweb
  • 3,795
  • 4
  • 33
  • 64
  • Thanks very much. I independently came up with a similar solution earlier and it appears to do exactly what I want it to do. – rbobbington Jun 11 '12 at 20:24