5
votes

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?

3

3 Answers

1
votes

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

1
votes

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.

0
votes

This is an old question, but I just had the same issue as the OP, but in my case with Joomla 3.4.3.

After a lot of digging and testing, I discovered a solution for this that doesn't involve any plugin or core change:

If you put limitstart=0 in the URL, the pagination will restart for that page, and this solves the problem between menus.

The way to implement this could be either with javascript, or by overriding the menu module, I chose the override:

  1. I just need this in some menus, so I placed a CSS class into the menu link (edit the menu, and in the "Link Type" tab, place the CSS class in the "Link CSS Style" field), in my case it was " video-area" (without the quotes).
  2. Add override (add the module to the html folder of your template, in my case it was the menu module, so it was a matter of adding the mod_menu folder: templatefolder/html/mod_menu)
  3. In the override of the component part of the module (default_component.php), check to see if we have the CSS class, if so, add the extra query to the URL (I edited case 0):

    case 0: $paginationLinks = ""; if(isset($class) && strpos($class, ' video-area') !== false){ $paginationLinks = "?limitstart=0&limit=12"; } ?><a <?php echo $class; ?>href="<?php echo $item->flink; ?><?php echo $paginationLinks;?>" <?php echo $title; ?>><span><?php echo $linktype; ?></span></a><?php break;

That's it! it solved my problem, and even the pagination links have the extra query :)

BONUS: notice that I have &limit=12, this changes the limit for the pagination into 12 per page, without any extra code!, (before, I had a lot of code to implement this, and by adding this to the menu it calculates the correct page number and totals, and filters the query, nice one Joomla!)