This is last tutorial about adding comment at Joomla component. We will display list of comment below single posting (like usual blog, this site too).
- Open "hello.php" within joomla/components. Update viewHello() function with following bold code:
function viewHello($option)
{
$id = JRequest::getVar('id', 0);
$row =& JTable::getInstance( 'hello', 'Table');
$row->load($id);
if(!$row->published)
{
JError::raiseError( 404, JText::_('Invalid ID Provided'));
}
HTML_hello::viewHello($row, $option);
$db =& JFactory::getDBO();
$db->setQuery("SELECT * FROM #__hello_comment WHERE hello_id='$id'");
$rows = $db->loadObjectList();
foreach($rows as $row)
{
HTML_hello::showComment($row);
}
$user =& JFactory::getUser();
if($user->name)
{
$name = $user->name;
}
else
{
$name = '';
}
HTML_hello::showCommentForm($option, $id, $name);
}
- Open "hello.html.php", enter following function:
function showComment($row)
{
?>
<P>
<strong><?php echo $row->full_name; ?></strong>
<em><?php echo JHTML::Date($row->comment_date); ?></em>
</P>
<P><?php echo $row->comment_text; ?></P>
<?
}