Is your thread.php model has a belongsTo User ?
<?php print_r($threads); ?> is this prints the User array ? Andras Kende http://www.kende.com On Aug 17, 2010, at 11:22 AM, Andrew Alexander wrote: > I am attempting to create a forum in php. In my project I have tables: > threads, posts, users. And each post has a foreign key for a thread > and a user. In my thread view I want to replace the user_id field with > the corresponding username for each post. I've tried "echo > $post['User']['username'];" but that gives me an error. > > Is there a way to access the username variable from the thread view? > > > Here's the code I have in view now: > <?php > $i = 0; > foreach ($thread['Post'] as $post): > $class = null; > if ($i++ % 2 == 0) { > $class = ' class="altrow"'; > } > ?> > <tr<?php echo $class;?>> > <td><?php echo $post['subject'];?></td> > <td><?php echo $post['body'];?></td> > <td><?php echo $post['created'];?></td> > <td><?php echo $post['user_id']; ?></td> > <td class="actions"> > <?php echo $this->Html->link(__('View', true), > array('controller' > => 'posts', 'action' => 'view', $post['id'])); ?> > <?php echo $this->Html->link(__('Edit', true), > array('controller' > => 'posts', 'action' => 'edit', $post['id'])); ?> > <?php echo $this->Html->link(__('Delete', true), > array('controller' => 'posts', 'action' => 'delete', $post['id']), > null, sprintf(__('Are you sure you want to delete # %s?', true), > $post['id'])); ?> > </td> > </tr> > <?php endforeach; ?> > > 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 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
