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


Friday, June 25, 2010

Advance joomla component with table connection

You already know basic concept of joomla component. From today, we can study advance level of example which cover table connection and proper management of admin panel. Before start this lesson, ple download previous "simple example joomla component". and install it.


Ok now we are ready to going forward with this lesson. have u any target? or have u any thing which need to apply joomla? Yes as a Example we can define our requirement as follows.

Target - telephone number storing system
Table attributes - Your name / Your Email / Your Tp
Sql -
CREATE TABLE `jos_contactUs` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`your_name` VARCHAR( 100 ) NOT NULL ,
`your_email` VARCHAR( 100 ) NOT NULL ,
`your_tp` VARCHAR( 10 ) NOT NULL
)
step 01
manually run above sql on your DB

join with next lesson

wAp