phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Joomla - Component: Hello From Database at Front End

Tag: joomla, cms, Joomla Component   Category: PHP Framework
post: 08 Nov 2007 read: 4,799


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.

  1. Open your "hello.php" within "joomla/components/com_hello" directory.
  2. 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);
    }
    ?>
    
  3. 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


Series this article:
Joomla - Component: Create Hello World Component on Front End
Joomla - Component: Create Hello World Component on Back End
Joomla - Component: Registering Your Component in database
Joomla - Component: Create Component Link for Front End
Joomla - Component: Creating Toolbars
Joomla - Component: Available Toolbar Buttons
Joomla - Component: Creating the Database Table
Joomla - Component: Creating Form Input Data at Back End
Joomla - Component: Saving Data to Database
Joomla - Component: Creating a List Screen
Joomla - Component: Creating Advance List Screen
Joomla - Component: Editing Data
Joomla - Component: Deleting Data
Joomla - Component: Updating publish state
Joomla - Component: Hello From Database at Front End
Joomla - Component: a Hello page
Joomla - Component: Generating Friendly Links
Joomla - Component: Adding Comment ( Create Table )
Joomla - Component: Adding Comment (Create Form)
Joomla - Component: Adding Comment ( Insert Data )
Joomla - Component: Adding Comment ( Displaying Comments )
Joomla: Fast Road to Understand Component Programming

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


619
posting