Hi,
I have written a component to display some data in database on the front
end in the form of tables. Now I want to add pagination to it. I tried
every tutorial or guide I could find to get the result, but no use.
*pagination->getPagesCounter()* and *pagination->getPagesLinks()* won't
work at all.
*pagination->getLimitBox()* displays the box, but nothing happens when it
is operated.
I am giving here the code I currently have.
*models\members.php*
<?php
defined( '_JEXEC' ) or die;
jimport('joomla.application.component.modellist');
class ExploreModelMembers extends JModelList
{
var $_data = null;
var $_total = null;
var $_pagination = null;
function __construct()
{
parent::__construct();
$application = JFactory::getApplication() ;
$config = JFactory::getConfig() ;
$limitstart = JRequest::getInt( 'limitstart', 0 );
$limit = $application->getUserStateFromRequest( 'global.list.limit',
'limit', $config->getValue('config.list_limit'), 'int' );
$this->setState('limitstart', $limitstart);
$this->setState('limit', $limit);
}
function _loadData()
{
if (empty($this->_data) && empty($this->_total))
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('m.*, f.*');
$query->from('#__explore_members AS m, #__explore_families AS f');
$query->where('m.family_id = f.family_id');
$this->_db->setQuery($query);
$this->_data = $this->_db->loadObjectList();
$this->_total = count( $this->_data ) ;
}
return $this->_data ;
}
function getData()
{
$this->_loadData() ;
$limitstart = $this->getState('limitstart');
$limit = $this->getState('limit');
return array_slice( $this->_data, $limitstart, $limit );
}
function getTotal()
{
return $this->_total;
}
function getPagination()
{
$this->_loadData() ;
if (empty($this->_pagination))
{
jimport('joomla.html.pagination');
$limitstart = $this->getState('limitstart');
$limit = $this->getState('limit');
$total = $this->getTotal();
$this->_pagination = new JPagination( $total, $limitstart, $limit );
}
return $this->_pagination;
}
}
*views\members\view.html.php*
<?php
defined( '_JEXEC' ) or die;
jimport( 'joomla.application.component.view');
class ExploreViewMembers extends JView
{
protected $header;
protected $items;
protected $pagination;
public function display($tpl = null)
{
$this->header = 'List of Members';
$items = $this->get('Data');
$this->assignRef( 'items', $items );
$pagination = $this->get('Pagination') ;
$this->assignRef( 'pagination', $pagination );
parent::display($tpl);
}
}
*views\members\tmpl\default.php*
<?php defined( '_JEXEC' ) or die; ?>
<h1><?php echo $this->header ?></h1>
<?php echo $this->pagination->getLimitBox(); ?>
<?php echo $this->pagination->getPagesCounter(); ?>
<table style="border:none; width:100%; line-height:25px;">
<tr style="font-weight:bold; text-align:center">
<td>Name</td><td>Family Contact</td><td>Family
Address</td><td>Occupation</td>
</tr>
<?php foreach ($this->items as $item): ?>
<tr>
<td style="padding-left: 5px">
<?php echo $this->escape($item->member_firstname) ?> <?php echo
$this->escape($item->member_middlename) ?> <?php echo
$this->escape($item->member_surname) ?>
</td>
<td style="padding-left: 5px">
<?php echo $this->escape($item->family_ph_r) ?>
</td>
<td style="padding-left: 5px">
<?php echo $this->escape($item->family_address) ?>
</td>
<td style="padding-left: 5px">
<?php echo $this->escape($item->occupation_cat) ?>
</td>
</tr>
<?php endforeach ?>
</table>
<?php echo $this->pagination->getPagesLinks(); ?>
Please help me out. I am out of brains on this. :(