Skip to content

Instantly share code, notes, and snippets.

@swthate
Created May 2, 2014 18:53
Show Gist options
  • Save swthate/f5efe962a2228422793d to your computer and use it in GitHub Desktop.
Save swthate/f5efe962a2228422793d to your computer and use it in GitHub Desktop.
Display Comment Username
<?php
// debug($commentAuthor['User']);
array(
'password' => '*****',
'id' => '9',
'username' => 'Steven',
'created' => '2014-04-25 20:42:51',
'modified' => '2014-04-25 20:42:51'
)
// debug($commentAuthor['User']['username']);
'Steven'
<?php
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->Job->exists($id)) {
throw new NotFoundException(__('Invalid job'));
}
$options = array('conditions' => array('Job.' . $this->Job->primaryKey => $id));
$this->set('job', $this->Job->find('first', $options));
$this->loadModel('User');
$this->set('commentAuthor', $this->User->findById('9'));
}
<!-- File: /app/View/Jobs/view.ctp -->
<!-- Comments List ................................... -->
<h3>Comments</h3>
<?php foreach ($job['Comment'] as $comment): ?>
<div class="panel">
<h4><?php echo $comment['title'];?></h4>
<p>By <?php echo $comment['user_id'];?></p>
<p><?php echo $comment['text'];?></p>
</div>
<?php endforeach; ?>
<?php debug($commentAuthor['User']['username']); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment