Hi Mitchell,

I guess that 'user_id' is the foreign key to the users table?
If so, you should add a 'hasOne' relationship in the comments model
(comments have one user).
When that is working, cake automatically gets the corresponding user
data when you use find().
Now you can pass the results to the view and get the username with
$post['User']['username'].

-flosky

On 17 Okt., 11:03, euromark <[email protected]> wrote:
> did you add
> $this->displayField = 'username';
> to the user model?
>
> On 17 Okt., 02:58, Mitchell Vargo <[email protected]> wrote:
>
>
>
>
>
>
>
> > Is there an easy way of replacing the user_id to username in a view
> > that looks like this?
>
> > <div class="related">
> >         <h3><?php echo __('Related Comments');?></h3>
> >         <?php if (!empty($post['Comment'])):?>
> >         <table cellpadding = "0" cellspacing = "0">
> >         <tr>
> >                 <th><?php echo __('Id'); ?></th>
> >                 <th><?php echo __('Title'); ?></th>
> >                 <th><?php echo __('Content'); ?></th>
> >                 <th><?php echo __('Username'); ?></th>
> >                 <th class="actions"><?php echo __('Actions');?></th>
> >         </tr>
> >         <?php
> >                 $i = 0;
> >                 foreach ($post['Comment'] as $comment): ?>
> >                 <tr>
> >                         <td><?php echo $comment['id'];?></td>
> >                         <td><?php echo $comment['title'];?></td>
> >                         <td><?php echo $comment['content'];?></td>
> >                         <td><?php echo $comment['user_id']; ?></td> 
> > <------- I want to
> > change this into the users username
> >                         <td class="actions">
> >                                 <?php echo $this->Html->link(__('View'), 
> > array('controller' =>
> > 'comments', 'action' => 'view', $comment['id'])); ?>
> >                                 <?php echo $this->Html->link(__('Edit'), 
> > array('controller' =>
> > 'comments', 'action' => 'edit', $comment['id'])); ?>
> >                                 <?php echo 
> > $this->Form->postLink(__('Delete'), array('controller'
> > => 'comments', 'action' => 'delete', $comment['id']), null, __('Are
> > you sure you want to delete # %s?', $comment['id'])); ?>
> >                         </td>
> >                 </tr>
> >         <?php endforeach; ?>
> >         </table>
> > <?php endif; ?>
> > </div>

-- 
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

Reply via email to