Joomla - Component: Creating a List Screen



In this tutorial, we will build a screen that lists all of the messages in database. We start with simple grid.

  1. Open "admin.hello.html.php" file and replace showHello() with following code:
    <?
    	function showHello($rows){
    	?>
    	<form action="index.php" 
               method="post" name="adminForm">    
        <table class="adminlist">
        <thead>
        	<tr>
            	<th width="20">
                <input type="checkbox" name="toggle"
                value="" 
     onclick="checkAll(<?php echo count($rows)?>)">
                </th>
                <th width="50" class="title">ID</td>
                <th>Message</th>
                <th nowrap="nowrap">Published</th>
            </tr>
        </thead>
        <?php
        $k = 0;
    	for($i=0, $n=count($rows); $i < $n ; $i++)
    	{
    		$row = &$rows[$i];
    		$checked 	= JHTML::_('grid.id', $i, $row->id);
    		$published 	= JHTML::_('grid.published', $row, $i); 
    		?>
            <tr class="<?php echo "row$k"; ?>">
            	<td><?php echo $checked?></td>
            	<td><?php echo $row->id?></td>
            	<td><?php echo $row->message?></td>            
            	<td><?php echo $published?></td>            
            </tr>
            <?
    		$k = 1 - $k;
    	}
    	?>
        </table>
        <input type="hidden" name="option" value="com_hello">
        <input type="hidden" name="task" value="">    
        <input type="hidden" name="boxchecked" value="0">    
        </form>
        <?php
    	}
    ?>
    
  2. Open admin.hello.php, replace showHello() with following code:
    function showHello(){
        $db =& JFactory::getDBO();
    	$query = "SELECT * FROM #__hello";
    	$db->setQuery( $query );
    	$rows = $db->loadObjectList();
    	if($db->getErrorNum()){
    		echo $db->stderr();
    		return false;
    	}
     	HTML_contact::showHello($rows);
    }
    
When you open http://localhost/joomla/administrator/index.php?option=com_hello
Joomla: list screen


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


Tag: joomla, cms, Joomla Component Category: PHP Framework Post : November 05th 2007 Read: 14,249 Bookmark and Share

blog comments powered by Disqus