Backend pagination problem in joomla1.7 component development

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???

Views: 377

Replies to This Discussion

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...

I don't think you need all of the pagination code for 1.7. The code you have here looks more like what you would need for 1.5. I'd suggest you look at the com_weblinks core application for how they do it. 1.7 does most of the pagination chores for you, though you do have to put some things into your default.php or the form.php.

Thaks for your reply.

@Daniel Dimitrov

 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.

RSS

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service