Wednesday, June 30, 2010

Advance joomla component with table connection part 1

The following image shows the appearance of the admin panel of our component. Ok, let's try to load the table data [jos_contactUs] to here. For that we need to modify default.php form with the following code: -



com_lanka1->views->lanka1s->tmpl->default.php


<?php defined('_JEXEC') or die('Restricted access'); ?>
<?php
/**
* Google Map default controller
*
* @package Joomla.component
* @subpackage Components
* @link http://inetlanka.com
* @license GNU/GPL
* @auth inetlanka web team - [ info@inetlanka.com / wapnishantha@gmail.com ]
*/
?>
<form action="index.php" method="post" name="adminForm">
<div id="editcell">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?php echo JText::_( 'ID' ); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
</th>
<th>
<?php echo JText::_( 'Telephone List' ); ?>
</th>
</tr>
</thead>
<?php
$k = 0;
for ($i=0, $n=count( $this->items ); $i < $n; $i++) {
$row = &$this->items[$i];
$checked = JHTML::_('grid.id', $i, $row->id );
$link = JRoute::_( 'index.php?option=com_lanka1&controller=lanka1&task=edit&cid[]='. $row->id );
?>
<tr class="<?php echo "row$k"; ?>">
<td>
<?php echo $row->id; ?>
</td>
<td>
<?php echo $checked; ?>
</td>
<td>
<a href="<?php echo $link; ?>"><?php echo $row->your_name; ?></a>
</td>
</tr>
<?php
$k = 1 - $k;
}
?>
</table>
</div>

<input type="hidden" name="option" value="com_lanka1" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="controller" value="lanka1" />
</form>





The last part of above code is very important, from the
<input type="hidden" name="option" value="">a1" />
to the
</form>






Note only default.php but also view.html.php is essential to success this stage

com_lanka1->views->lanka1s->view.html.php

<?php
/**
* Lanka1 default controller
*
* @package Joomla.component
* @subpackage Components
* @link http://inetlanka.com
* @license GNU/GPL
* @auth inetlanka web team - [ info@inetlanka.com / wapnishantha@gmail.com ]
*/

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );

/**
* lanka1 View
*
* @package Joomla.component
* @subpackage Components
*/
class Lanka1sViewLanka1s extends JView
{
/**
* lanka1 view display method
* @return void
**/
function display($tpl = null)
{
JToolBarHelper::title( JText::_( 'Lanka1' ), 'generic.png' );
JToolBarHelper::deleteList();
JToolBarHelper::editListX();
JToolBarHelper::addNewX();

// Get data from the model
$items = & $this->get( 'Data');

$this->assignRef('items', $items);

parent::display($tpl);
}
}




This is first time we've used a module . On an MVC system, module is used to make a relationship between a table and a component.

In our example, we use two modules, lanka1.php and lanka1s.php as follows
com_lanka1->models->lanka1.php
com_lanka1->models->lanka1s.php

Click on the following link to go to the next lesson:

wAp


2 comments:

  1. And what whould I do if I use a php form software? How can I change it?

    ReplyDelete