Broken pagination

Joomla versions 2.5, 1.7 and 1.6 are all end-of-life since December 31st 2014 and are no longer supported. Please use Joomla 3.x instead.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
User avatar
lgalarra
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Fri Jul 27, 2007 4:05 pm

Broken pagination

Post by lgalarra » Thu Sep 11, 2014 6:27 pm

Dear Joomla! community,

I am Joomla! extensions developer and one of my users has a Joomla! 2.5 that was upgraded from Joomla! 1.5. After upgrading the user installed my extension (J!Research). For some reason, pagination is broken in this website although it has been widely tested in different server configurations. I have a standard view-model that displays a list of publications and contains some filters. Those filters are implemented using the standard Joomla! style recommendations (available in docs and forums), that is, the filters (drop-down lists) are fields in a form that trigger submission when changed and the values of the form fields are stored in the user state. The populateState method of my model is provided:

Code: Select all

protected function populateState() {
        // Initialize variables.
        $mainframe = JFactory::getApplication('site');
        $params = $mainframe->getParams('com_jresearch');

        $this->setState('com_jresearch.publications.filter_search', $mainframe->getUserStateFromRequest($this->_context.'.filter_search', 'filter_search'));
        
		//My publications
    	$filter_show = $params->get('filter_show', 'all');		
    	$user = JFactory::getUser();
    	if($filter_show == "my" && !$user->guest)
    	{
    		//Only in this case, force the model (ignore the filters)	    	
    		$member = JTable::getInstance('Member', 'JResearch');
    		$member->bindFromUsername($user->username);
    		JRequest::setVar('filter_author', $member->id);    	 			
    	}    	
        
        $this->setState('com_jresearch.publications.filter_author', $mainframe->getUserStateFromRequest($this->_context.'.filter_author', 'filter_author'));        
        $this->setState('com_jresearch.publications.filter_year', $mainframe->getUserStateFromRequest($this->_context.'.filter_year', 'filter_year'));        
        $this->setState('com_jresearch.publications.filter_area', $mainframe->getUserStateFromRequest($this->_context.'.filter_area', 'filter_area'));        
        
        $filter_pubtype = $params->get('filter_pubtype', 'all');    	    	
        if($filter_pubtype != 'all'){
	        JRequest::setVar('filter_pubtype', $filter_pubtype);
        }
        
        $this->setState('com_jresearch.publications.filter_pubtype', $mainframe->getUserStateFromRequest($this->_context.'.filter_pubtype', 'filter_pubtype'));        
        $this->setState('com_jresearch.publications.filter_team', $mainframe->getUserStateFromRequest($this->_context.'.filter_team', 'filter_team'));        
        
		parent::populateState();        
    }
As you can I see, I set the model state using the method JApplication::getUserStateFromRequest() which I know it is suitable for this case. If the value of the filters in the form changes, the state is updated from the values of the associated request variable, otherwise the old state is retained and reported when needed. Now, the filters work fine, the problem is that pagination is broken when the list has been filtered. If I click one of the page links at the bottom the values of my filters are reset, which, as far as I know, should not happen (since the old state should be remembered). I performed some debugging in the function JApplication::getUserStateFromRequest() and found out that the old state is forgotten by JApplication::getUserState() (in charge of retrieving the old state). I also noticed my pagination links seem correct, that is, if my url is xyz.com/publications, the links are xyz.com/publications?start=X, where the start request variable is associated to a model state key (not show here but set in parent::populateState()).

Has anybody experienced a similar problem before? The site is using PHP 5.2.17, Joomla 2.5.24, cgi-fcgi as the PHP interface with the webserver and Apache/2.4.4. If somebody has an idea or have heard of something like this, I would appreciate to share his experience with me. Thanks for attention and help!

Best,
Luis

Locked

Return to “Migrating and Upgrading to Joomla! 2.5”