Alternatively we use the previous value, and if that is not set we use the default
value defined in the application configuration.
The limitstart variable is retrieved from the user state value $option, plus
.limitstart. $option is the component name, for example com_content. If we
build a component that has multiple lists we should add an extra level to this,
normally named after the entity.
If a value is set in the request value limitstart (part of the listFooter) we use that
value. Alternatively we use the previous value, and if that is not set we use the
default value 0, which will lead us to the first page.
At this stage you might be wondering why we handle this in the constructor and
not the getPagination() method. As well as using these values for the JPagination
object, we also need to use them when getting data from the database.
Assuming we are using a method called getData() to retrieve the itemized data, our
method might look like this:
/**
* Get itemized data
*
* @access public
* @return array
*/
function getData()
{
if (empty($this->_data))
{
$query = $this->_buildQuery();
$limitstart = $this->getState('limitstart');
$limit = $this->getState('limit');
$this->_data = $this->_getList($query, $limitstart, $limit);
}
return $this->_data;
}
Rendering Output
[ 228 ]
This method uses the private _buildQuery() method that we discussed earlier.
Pages:
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315