Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joomla pagination across different components

Because pagination is using getUserStateFromRequest method to get the limit and limitstart variable, I'm having a problem where as I navigate from one component to another, I'm shown a no items found message.

To clarify, I have a products component that has 3 pages worth of products listed. Then I have a branches component with 2 pages worth of branch information. So if I navigate to the third page in the products list, and then go to the branches component, nothing is displayed.

Has anyone any idea how to stop this from happening? Any way to maybe clear the session data?

like image 553
user1634781 Avatar asked Nov 03 '22 14:11

user1634781


2 Answers

What I ended up doing was this, in line 624 in libraries/joomla/application/application.php file I added the following lines

$this->setUserState('option','default');

        $curr_comp = JRequest::getCmd( 'option' );;


        if($this->getUserState('option') != $curr_comp)
        {
            $this->setUserState($option . 'limitstart',0);
            $this->setUserState('option',$curr_comp);

        }

so the whole function reads this,

public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
    {

        $this->setUserState('option','default');

        $curr_comp = JRequest::getCmd( 'option' );


        if($this->getUserState('option') != $curr_comp)
        {
            $this->setUserState($option . 'limitstart',0);
            $this->setUserState('option',$curr_comp);

        }
        $cur_state = $this->getUserState($key, $default);
        $new_state = JRequest::getVar($request, null, 'default', $type);


        // Save the new value only if it was set in this request.
        if ($new_state !== null)
        {
            $this->setUserState($key, $new_state);
        }
        else
        {
            $new_state = $cur_state;
        }

        return $new_state;
    }

This seems to be working fine at the moment. But please test before implementing on a live site

like image 182
user1634781 Avatar answered Nov 09 '22 12:11

user1634781


To prevent editing the core files, but with the effect limited to your extension (so other extensions could load at the wrong page, but not yours), and if your model extends modellist, override the getStart() method:

public function getStart()
{
    $store = $this->getStoreId('getstart');
    $input = JFactory::getApplication()->input;
    $start = $limitstart = $input->getInt('limitstart', 0);
    $this->setState('list.start', $limitstart); // maybe redundant

    $limit = $this->getState('list.limit');
    $total = $this->getTotal();
    if ($start > $total - $limit)
    {
        $start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
    }

    // Add the total to the internal cache.
    $this->cache[$store] = $start;
    return $this->cache[$store];
}    

If you want a solution that works system-wide and for all extensions, you should be able to override modellist with your implementation in a plugin. Start here.

like image 40
Riccardo Zorn Avatar answered Nov 09 '22 13:11

Riccardo Zorn