Hi,
I am new to joomla component development.Now i am creating a simple image gallery.I have created it sucessfully in joomla1.6. But a small pagination problem while using it in joomla 1.7.The backend pagination is not working. I am using the tutorial "http://blog.opensourcenetwork.eu/tutorials/guru/mvc-workflow-with-jpagination".i am including the code here.
In model :
<?php
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.application.component.model');
class ComponentnameModelModelname extends JModel
{
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' );
$limit = 1;
$this->setState('limitstart', $limitstart);
$this->setState('limit', $limit);
}
function _loadData()
{
if (empty($this->_data) && empty($this->_total))
{
$album = JRequest::getVar( 'album');
$query = "SELECT * FROM #__databasename WHERE albumname='".$album."'";
$this->_db->setQuery($query);
$this->_data = $this->_db->loadObjectList();
$this->_total = count( $this->_data ) ;
}
return $this->_data ;
}
function getData()
{
$this->_loadData() ;
$album = JRequest::getVar( 'album');
$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;
}
}
?>
In views/photos/tmpl/default.php
<?php
defined('_JEXEC') or die( 'Restricted access' );
$host = JURI::root();
jimport('joomla.html.pagination');
?>
<form name="adminForm" method="post">
<div class = "photo">
<img src="<?php echo $host?>images/<?php echo $item->image;?>" height = "300" width = "300" alt = "no image" />
</div>
<div id="photopagination">
<?php echo $this->pagination->getPageslinks();?>
</div>
<div style="display:none">
<?php echo $this->pagination->getListFooter(); ?>
</div>
</form>
I am using a form named admin form in template file.When i add the getListFooter function only,pagination is working in backend.Is ant modification needs to be done in joomla 1.7 for working this???
Tags:
Permalink Reply by Daniel Dimitrov on July 30, 2011 at 6:38am I think that the best tutorial that you can have on jpagination is this one:
http://docs.joomla.org/Using_JPagination_in_your_component
I flew over the tutorial you are using and I find it bad. You are getting all the records from the database, then doing arra_slice? What happens when you have 500 000 records in the database???
Do the count and get the total number of entries...
Permalink Reply by Tom Fuller on July 30, 2011 at 12:19pm
Permalink Reply by Shemeena on August 1, 2011 at 12:11am Thaks for your reply.
I have followed the tutorial that you have suggested.The thing is that the first page displays correctly,the navigation links are also present in the backend.But the pages links and the next and previous buttons are not working.When i click on the next button one "#' is added to the url and it displays the first page itself[in joomla 1.7].Its working perfectly in joomla1.6.
© 2012 Created by Amy Stephen.