Page 1 of 2

Front End Pagination Problem

Posted: Thu Apr 10, 2008 3:28 pm
by tfuller
The pagination schema works on the back end fine but there is a problem on the front end.

The problem is going back to page one of the results.

On the backend the list correctly returns to LIMIT 0,0

But on the front end, using the exact same model as the backend, hitting Start or page 1 of results returns the present page. LIMIT also stays on the current page of results.

So the url, for instance, http://www.calvarychapelnewberg.org/ind ... itstart=20

Goes to page 2.

But then if you click on:
http://www.calvarychapelnewberg.org/ind ... Itemid=285

The front end list stays on page 2 of results and will not reset LIMIT.

I thought it was my coding error (and maybe it is) but there is a definite difference between how backend admin lists work and front end lists since I used the same model for back and front end with different results.

Is there someone who can enlighten as to code differences in pagination between front and back end?

Thanks!

tom

Re: Front End Pagination Problem

Posted: Sun Jul 13, 2008 9:29 pm
by khaotik
I have the same damn problem... goes to second page, but not back to the first.
I've observed something interesting: while in the backend doesn't apear any variables in the url's of the page buttons, they appear in the frontend. If you go to page one, and put your cursor above the link to the second page, the variable appear in the url "limitstart=5"... Strange isn't? i think i will write down some code to deal with the link creation of the pagination... I mean, is not that hard, and besides, what else can I do? :D

Re: Front End Pagination Problem

Posted: Sun Jul 13, 2008 11:05 pm
by airton
Hi Tom,

Sorry for the long time without an answer to your question.

I can see from the links you posted that it's still an issue for you. If so, would you please use the Forum Post Assistant link in the pink box on top of this thread and post the results here? It will help a lot in diagnosing your problem.

khaotik, could you please do the same and, if possible, provide some example URLs for us to test it?

Thank you guys!

Regards,

Airton

Re: Front End Pagination Problem

Posted: Mon Jul 14, 2008 3:14 pm
by tfuller
Didn't know anything about the Forum Assistant. Pretty cool! Here is the post generation:

Problem Description:
Front page pagnination will not allow return to first page of results (no LIMITSTART) after navigating to any other page of results. Same model code works correctly on the admin backend.



Diagnostic Information
Joomla! Version: Joomla! 1.5.4 Production/Stable [ Naiki ] 6-July-2008 22:00 GMT
configuration.php: Writable (Mode: 775 ) | RG_EMULATION: N/A
Architecture/Platform: Linux infong 2.4 #1 SMP Wed Sep 26 00:19:50 CEST 2007 i686 GNU/Linux Linux infong 2.4 #1 SMP Wed Sep 26 00:19:50 CEST 2007 i686 GNU/Linux ( Linux infong 2.4 #1 SMP Wed Sep 26 00:19:50 CEST 2007 i686 GNU/Linux) | Web Server: Apache/1.3.34 Ben-SSL/1.55 ( www.joomlaoregon.org ) | PHP Version: 4.4.8
PHP Requirements: register_globals: Disabled | magic_quotes_gpc: Enabled | safe_mode: Disabled | MySQL Support: Yes | XML Support: Yes | zlib Support: Yes
mbstring Support (1.5): Yes | iconv Support (1.5): Yes | save.session_path: Writable | Max.Execution Time: 30 seconds | File Uploads: Enabled
MySQL Version: 5.0.51-log ( db1410.perfora.net via TCP/IP )

Extended Information:
SEF: Disabled (without ReWrite) | FTP Layer: Enabled | htaccess: Not Implemented
PHP/suExec: User and Web Server accounts are the same. (PHP/suExec probably installed)
PHP Environment: API: cgi | MySQLi: No | Max. Memory: 12M | Max. Upload Size: 20M | Max. Post Size: 8M | Max. Input Time: -1 | Zend Version: 1.3.0
Disabled Functions:
MySQL Client: 5.0.32 ( latin1 )

Re: Front End Pagination Problem

Posted: Mon Jul 14, 2008 8:48 pm
by airton
Hi Tom,

Thanks for posting those results. It will help a lot.

I have a few more questions though.

- Are there actually articles that are not being shown because they belong to page 1 or is it just the indication of page 2 of 26 that is wrong and should be 1 of 26 or 1 of 25?

- What kind of view has the problem? Article Layout, Category Blog, Category List, etc, or all of them?

Thanks for raising this issue.

Regards,

Airton

Re: Front End Pagination Problem

Posted: Mon Jul 14, 2008 9:15 pm
by tfuller
1. Yes - there are actually articles not being shown. When you first go to the listing it is sorted normally by date descending (though you can change that). If you go to page 2 then back to page one the results from page 2 "stick" and you can no longer see the results from page 1

2. As for the layout - its a third party component but it's a listing of links to articles. It's in a component/view/studieslist/tmpl/default.php

This is my pagination function in the model:

Code: Select all

function getPagination()
	{
		// Lets load the content if it doesn't already exist
		if (empty($this->_pagination))
		{
			jimport('joomla.html.pagination');
			$total = $this->getTotal();
			$limitstart = $this->getState('limitstart');
			$limit = $this->getState('limit');
			$this->_pagination = new JPagination( $total, $limitstart, $limit );
			
		}

		return $this->_pagination;

Re: Front End Pagination Problem

Posted: Mon Jul 14, 2008 10:20 pm
by airton
tfuller wrote:1...
2. As for the layout - its a third party component but it's a listing of links to articles. It's in a component/view/studieslist/tmpl/default.php
...
So, this isn't a Joomla! issue. The problem resides in your pagination function, as can be noted in other parts of your site where the component is not used and the pagination works as expected.

I suggest you look at how pagination is done in other core files and if replacing it solves your problem. maybe the code you based your function has subsequently been fixed.

Hope this helps.

Best regards,

Airton

Re: Front End Pagination Problem

Posted: Mon Jul 14, 2008 10:26 pm
by tfuller
Thanks, Airton - I based my code on other core components so I expected it to work correctly but it is not a Joomla core issue. Thanks for your attention!

Tom

Re: [NOT A JOOMLA! ISSUE] Front End Pagination Problem

Posted: Mon Jul 14, 2008 10:56 pm
by airton
Sorry if i couldn't be of much help here. I'm not a very skilled PHP coder and I'm still learning J!1.5 framework, but as a volunteer to help Joomla! Bug Squad I had to step into this issue.
Hopefully you'll find a solution reviewing your code or get some more skilled person to help you out, after all this is what this community is all about.

I wish you the best of luck!

Regards,

Airton.

Re: Front End Pagination Problem

Posted: Mon Jul 14, 2008 11:11 pm
by tfuller
No problem - this issue had kind of fallen off my radar but now I'm reviewing the core code and noticing some different ways of doing it. I took my code from James Kennard's great book Mastering Joomla! 1.5 but I notice now that the com_content uses different code in their model and in their views to accomplish pagination on the front end so I'll work at implementing that and see if it works!

Cheers.

Tom

Re: Front End Pagination Problem

Posted: Tue Jul 15, 2008 4:17 pm
by tfuller
Just in case someone else has problems with a third party component not paginating correctly on the front end - here is how I solved the problem - using the model from weblinks in 1.5.3

This is in the list display model:

Code: Select all

function __construct()
	{
		parent::__construct();

		global $mainframe, $option;
		$config = JFactory::getConfig();
		// Get the pagination request variables
		$this->setState('limit', $mainframe->getUserStateFromRequest('com_biblestudy.limit', 'limit', $config->getValue('config.list_limit'), 'int'));
		$this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));

		// In case limit has been changed, adjust limitstart accordingly
		$this->setState('limitstart', ($this->getState('limit') != 0 ? (floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit')) : 0));
		
	}
function getData()
	{
		// Lets load the data if it doesn't already exist
		if (empty( $this->_data ))
		{
			$query = $this->_buildQuery();
			$this->_data = $this->_getList( $query, $this->getState('limitstart'), $this->getState('limit') );
		}

		return $this->_data;
	}
function getPagination()
	{
		// Lets load the content if it doesn't already exist
		if (empty($this->_pagination))
		{
			jimport('joomla.html.pagination');
			$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
			
						
		}

		return $this->_pagination;
	}
Then in the list display template default.php:

Code: Select all

echo '   '.JText::_('Display Num').' ';
	echo $this->pagination->getLimitBox();
	echo $this->pagination->getPagesLinks();
	echo $this->pagination->getPagesCounter();

Re: Front End Pagination Problem

Posted: Sat Oct 18, 2008 2:33 pm
by ashelby
I was getting the same error when trying to go back to page one. I pulled my example out of a packt publisher "mastering joomla" book. It seems the $limitstart in the construct was causing my issue.

I changed the following:

Code: Select all

$limitstart = $mainframe->getUserStateFromRequest($option.'limitstart', 'limitstart', 0, 'int');
$this->setState('limitstart', $limitstart);
To what you have:

Code: Select all

$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
$this->setState('limitstart', $limitstart);
And it works like magic. Okay, it's just sensible coding.

Apparently it looks like the limitstart in the first part will just keep getting set to the last request, which I guess doesn't change when you click on page 2 or next.

However, the limitstart does get pass in the JRequest so that is where it is pulling it from on subsequent paging through lists. Thank goodness I found this thread.

Thanks!

Re: Front End Pagination Problem

Posted: Sat Oct 18, 2008 3:32 pm
by tfuller
That's great! It took me forever to find a solution and I thought I was going mad.

Re: Front End Pagination Problem

Posted: Wed Jan 07, 2009 8:03 am
by cambler
Thank you! I had this exact same problem with from-scratch code that made the same mistake. I was persisting limitstart across the request, so the code in pagination that removed it from the arguments on the URL simply meant that the persisted value stuck around.

This thread was my lightbulb moment :-)

Re: Front End Pagination Problem

Posted: Thu Jan 15, 2009 10:10 am
by homemade
Just wanted to say thanks for this blog. I also thought I was going crazy.

Re: Front End Pagination Problem

Posted: Wed Feb 04, 2009 12:08 pm
by amazeika
I had the same issue and got it solved with the modification of $limitstart in the model constructor posted here. Before finding this post, I came up to the solution thanks to this book: "Learning Joomla! 1.5 Extension Development". However, the non working code is the one you find in "Mastering Joomla 1.5 " and also here: http://docs.joomla.org/Using_JPaginatio ... _component. Perhaps a more experimented Joomla developer could help us understand ???.

Thanks.

Re: Front End Pagination Problem

Posted: Fri May 15, 2009 9:26 pm
by billengle
I was using the same book to build my Pagination and came across the issue when I would have two different views using pagination. Say I clicked on page 4 of one view and went back to my other view which only had 2 pages of data. No data would display because it was stuck on page 4 which doesn't exist.

Changing to this fixed my issue.

Code: Select all

$limitstart = JRequest::getVar('limitstart', 0, '', 'int');

Re: Front End Pagination Problem

Posted: Tue Jun 16, 2009 6:24 am
by dannygsam
Thanks a lot for the code.. I had the exact same problem.. i replaced the code and it works great.. was hitting my head for a week on this

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 1:25 am
by elvenfriend
I have the same problem and i want to know which files did u edit???

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 2:47 pm
by tfuller
This happens in your model files.

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 5:48 pm
by naturalcrusader
The issue i am having is that the front end is using links instead of submits. On the backend it will 'submit' using javascript, on the front end it is using a link to go back to index.php?limitstart=## .. this is a problem as I cannot keep my component, view, and task set.

So is this a bug? Is this something I have to change the source code for? Is this something I will have to try and just recreate in the module instead of using the 'built-in' pagination?

thanks!

or do they expect you to use sessions??

in playing around with it - i noticed something else -->

if I don't change the number of listed items the above holds true. but, when I changed the view to list 30 items, it fixed all of the links to include the task, controller, view...????

I thought of trying it with different numbers of items shown - this time all did not work (including the 30 view)

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 6:46 pm
by tfuller
If you are using an href link you will need to set at least the component and view and limitstart. Your model should grab limitstart from the request variable.

index.php?option=com_yourcomponent&view=yourview&limitstart=10

There is no "built in pagination" other than the presentation in the footer. Your model pretty much has to handle it, so it needs to get the component/view/limit variables from somewhere. You can set them by JRequest::setVar('myvariable', 'int'); etc within your view, or you can just include them in the href link.

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 7:01 pm
by naturalcrusader
I am using the built in pagination (JPagination) - I use the following on both the back end and the front with different results

<tfoot>
<tr>
<td colspan="12" align='center' ><?php echo $this->pagination->getListFooter(); ?></td>
</tr>
</tfoot>

on the back it is as normal (with javascript submitting the links):

<a href="#" title="1" onclick="javascript: document.adminForm.limitstart.value=0; submitform();return false;">1</a>

however on the front:

<a title="2" href="[domain]/index.php?limitstart=20" class="pagenav">2</a>

in the view (in both front/back):

function display($tpl = null)
{
$records = & $this->get( 'Data');
$pagination =& $this->get('Pagination');
$this->assignRef('records', $records);
$this->assignRef('pagination', $pagination);
parent::display($tpl);
}

in the model (both again)

var $_total = null;
var $_pagination = null;

function __construct()
{
parent::__construct();

global $mainframe, $option;

// Get pagination request variables
$limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
$limitstart = JRequest::getVar('limitstart', 0, '', 'int');

// In case limit has been changed, adjust it
$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);

$this->setState('limit', $limit);
$this->setState('limitstart', $limitstart);
}


function getTotal()
{
// Load the content if it doesn't already exist
if (empty($this->_total)) {
$query = $this->_buildQuery();
$this->_total = $this->_getListCount($query);
}
return $this->_total;
}
function getPagination()
{
// Load the content if it doesn't already exist
if (empty($this->_pagination)) {
jimport('joomla.html.pagination');
$this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
}
return $this->_pagination;
}

// same exact code in both the front and back with different results

the problem is I WANT it to post - but it is giving me HREF links instead of the submits. so do I need to change the JPagination class or is there someother way to do it?

thanks for your help!

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 7:56 pm
by tfuller
I've never gotten a good explanation as to why the JPagination works differently on the front end.

As for me, I added this code to my model:

Code: Select all

// In case we are on more than page 1 of results and the total changes in one of the drop downs to a selection that has fewer in its total, we change limitstart

if ($this->getTotal() < $this->getState('limitstart')) {$this->setState('limitstart', 0,'','int');}

at the bottom of the construct function. It seemed to do the trick.

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 9:56 pm
by naturalcrusader
naturalcrusader wrote: on the back it is as normal (with javascript submitting the links):

<a href="#" title="1" onclick="javascript: document.adminForm.limitstart.value=0; submitform();return false;">1</a>

however on the front:

<a title="2" href="[domain]/index.php?limitstart=20" class="pagenav">2</a>

Okay - I decided just to look at the source code:

libraries/joomla/html/pagination.php

line 439 starts the function _item_active.

Code: Select all

function _item_active(&$item)
	{
		global $mainframe;
		if ($mainframe->isAdmin())
		{
			if($item->base>0)
				return "<a title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=".$item->base."; submitform();return false;\">".$item->text."</a>";
			else
				return "<a title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=0; submitform();return false;\">".$item->text."</a>";
		} else {
			return "<a title=\"".$item->text."\" href=\"".$item->link."\" class=\"pagenav\">".$item->text."</a>";
		}
	}
the last return needs to be changed and an if statement added.

so the new function looks like:

Code: Select all

function _item_active(&$item)
	{
		global $mainframe;
		if ($mainframe->isAdmin())
		{
			if($item->base>0)
				return "<a title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=".$item->base."; submitform();return false;\">".$item->text."</a>";
			else
				return "<a title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=0; submitform();return false;\">".$item->text."</a>";
		} else {
			if($item->base == "")
				$item->base = 0;
			return "\n<a title=\"".$item->text."\"  onclick=\"javascript: document.adminForm.limitstart.value=".$item->base."; document.adminForm.submit(); \" >".$item->text."</a>";
		}
	}
solved all the problems - works great in the front end now! (the rest of the code all remained the same)

NaturalCrusader

PS - this assumes your form name is 'adminForm'

Re: Front End Pagination Problem

Posted: Wed Aug 26, 2009 10:20 pm
by tfuller
you should submit this as a bug fix in that forum. Great job!

Re: Front End Pagination Problem

Posted: Sun Aug 30, 2009 10:20 am
by saisimha
;)

Re: Front End Pagination Problem

Posted: Sun Aug 30, 2009 5:49 pm
by docmccoy
Why

Code: Select all

echo '&nbsp;&nbsp;&nbsp;'.JText::_('Display Num').'&nbsp;';
   echo $this->pagination->getLimitBox();
   echo $this->pagination->getPagesLinks();
   echo $this->pagination->getPagesCounter();
instead of

Code: Select all

echo $this->page->getListFooter();
?

Re: Front End Pagination Problem

Posted: Wed Jun 02, 2010 6:28 pm
by abstraktron
getListFooter() should work the same too. Thanks for this thread, very helpful.

Re: Front End Pagination Problem

Posted: Thu Jul 01, 2010 3:53 am
by doobiegirl09
works great saved my life :) I mean my time