Now, we will make up hello world at front end that we created at begining Joomla tutorial. We will place text that loaded from database.
- Open your "hello.php" within "joomla/components/com_hello" directory.
- Replace with the following code:
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
echo '<div class="componentheading">Hello World!</div>';
jimport('joomla.application.helper');
require_once(JApplicationHelper::getPath( 'html' ));
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.$option.DS.'tables');
switch( $task ){
default:
showPublishedHello($option);
break;
}
function showPublishedHello($option)
{
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__hello
WHERE published= '1' ORDER BY id DESC";
$db->setQuery( $query );
$rows = $db->loadObjectList();
if ($db->getErrorNum())
{
echo $db->stderr();
return false;
}
HTML_hello::showHello($rows, $option);
}
?>
- Then, create "hello.html.php" within "joomla/components/com_hello". Enter following code:
<?php
class HTML_hello
{
function showHello($rows, $option)
{ ?>
<table>
<?php
foreach($rows as $row)
{
$link = 'index.php?option='.$option.'&id='.
$row->id . '&task=view';
echo '
<tr>
<td>
<a href="'. $link .'">'. $row->message .'</a>
</td>
</tr>
';
}
?>
</table>
<?php
}
}
?>
Now, point your browser to http://localhost/joomla/index.php?option=com_hello