So I’ve been following this tutorial on JPagination and on the section about with JDatabase it has a variable $option on line 2 "$option.limit". (It hasn’t been referenced anywhere else on the page, I’m unsure on where this value is being declared/initialized).
$db =& JFactory::getDBO();
$lim = $mainframe->getUserStateFromRequest("$option.limit", 'limit', 14, 'int'); //I guess getUserStateFromRequest is for session or different reasons
$lim0 = JRequest::getVar('limitstart', 0, '', 'int');
$db->setQuery('SELECT SQL_CALC_FOUND_ROWS x, y, z FROM jos_content WHERE x',$lim0, $lim);
$rL=&$db->loadAssocList();
if (empty($rL)) {$jAp->enqueueMessage($db->getErrorMsg(),'error'); return;}
else {
////Here the beauty starts
$db->setQuery('SELECT FOUND_ROWS();'); //no reloading the query! Just asking for total without limit
jimport('joomla.html.pagination');
$pageNav = new JPagination( $db->loadResult(), $lim0, $lim );
foreach($rL as $r) {
//your display code here
}
echo $pageNav->getListFooter( ); //Displays a nice footer
I’ve had a look around joomla docs on pages such as this to see if the $option variable is relevant to the limitBox, because the limitbox
is what is setting the amount things to be displayed. But I haven’t had much luck.
Therefore I’m wondering how are you meant to obtain the information from the variable $option and/or the current selection from the LimitBox in JPagination.
Pastebin link to my implementation [expires in 24 hours]
The article is out of date in a few ways, it was originally written for J1.5 and assumes a lot of knowledge about the inner workings. I wouldn’t recommend it for J2.5.
Pagination is mostly automatic today if you’re following the J2.5 MVC and using it’s built-in (for the most) part user state mechanism. To start with, in J2.5 your model should should be extending
JModelListif you’re displaying a list of content items.JModelListextendsJModelby adding useful features for dealing with lists.One of these features is the
populateState()method, in it’s base state it will look after your list limits for you if you’re using a<select>namedlimit. It does this by managing the base userState for you, I would recommend reading through/administrator/com_contactand/libraries/joomla/application/component/modellist.php(Joomla API JModelList).populateState()is used to help the model keep track of basics for your component in a semi-automatic way. In addition to list limits, it will also track the search field and the sort column & it’s direction. If you extension needs to track other user states or override settings you can create apopulateState()in your model file – just remember to call the parent before hand so you still get the built-in benefits. e.g.For user state you can read more in this article (which also covers Pagination briefly) “How to use user state variables”