Joomla 2.5 pagination

I want to add pagination to my component, I created a simple model with a query. I must be missing something. What else do I need here?

MODEL
jimport('joomla.application.component.modellist');
class PaieskaModelPradinis extends JModelList
{
    public function getListQuery() 
    {
    $db = JFactory::getDBO();
    $query = "SELECT * FROM #__content";
    $db->setQuery( $query );
    $db->query( $query );
    $result = $db->LoadObjectList();
    return $result;
    }
}

VIEW

jimport( 'joomla.application.component.view');
class PaieskaViewPradinis extends JView
{
    protected $items;
    protected $pagination;
    function display ($tpl = null)
    {
        $this->items = $this->get('ListQuery');
        $this->pagination = $this->get('Pagination');

        parent::display($tpl);
    }
}
TPL
foreach ($this->items as $item) {
    echo $item->title;
}

      

Editorial staff:

I edited the bitcode so it works fine now, almost. Button mapping (number of lines to display) does not work. And I wonder if this part can be done differently?

    $limit      = JRequest::getVar('limit' , 25);
    $start      = JRequest::getVar('start' , 0);        
    $query      = "SELECT * FROM #__content LIMIT $start, $limit";

      

-

class PaieskaModelPradinis extends JModelList
{
    public function getItems() 
    {
        $db         = JFactory::getDBO();
        $limit      = JRequest::getVar('limit' , 25);
        $start      = JRequest::getVar('start' , 0);        
        $query      = "SELECT * FROM #__content LIMIT $start, $limit";
        $db->setQuery( $query );
        $db->query( $query );
        $lists = $db->LoadObjectList();

        return $lists;
    }
    function getPagination()
    {
        $main = JFactory::getApplication();
        $db         = JFactory::getDBO();
        $limit      = JRequest::getVar('limit' , 25);
        $limitstart = JRequest::getVar('limitstart', 0);

        $query      = "SELECT count(title) FROM #__content";
        $db->setQuery( $query );
        $total      = $db->loadResult();

                // include a pagination library

        jimport('joomla.html.pagination');
        $pagination = new JPagination($total, $limitstart, $limit);

        return $pagination;
    }
}

VIEW

jimport( 'joomla.application.component.view');
class PaieskaViewPradinis extends JView
{
    function display($tpl = null)
    {
        $this->items  = $this->get('items');
        $this->pagination = $this->get('pagination');

        parent::display($tpl);
    }
}

      

+2


source to share


2 answers


Revert the original code, not the edited version.



The getListQuery method only builds your database query, so you are not running your query here. Use com_weblinks as an example to build your model: https://github.com/joomla/joomla-cms/blob/2.5.x/components/com_weblinks/models/category.php

+1


source


go to this link http://docs.joomla.org/J1.5:Using_JPagination_in_your_component . I used Joomla pagination. You should be able to use Joomla pagination with ease if you follow the documentation correctly. By the way, it's very simple.



0


source







All Articles