Question

    $limit   = $this->_app->getUserStateFromRequest('global.list.limit', 'limit', $this->_app->getCfg('list_limit'), 'int');
    $limitstart = $this->_app->getUserStateFromRequest(OPTIOIN_NAME.'.limitstart', 'limitstart', 0, 'int');
    $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0); // In case limit has been changed

EG : PAGES 1 -> Set number of records be shown to 10 , When I go to PAGES 2 -> Pagination is automatically set 10. I want to have different pagination settings for different pages.

What it does is, it keep a global variable. so even when I moved to another page those pagination settings are saved and applied. if I change OPTIOIN_NAME.'.limitstart' or 'global.list.limit' to something else it gives me Warning: Attempt to assign property of non-object in D:\wamp\www\jink\libraries\joomla\registry\registry.php on line 342. How can I fix this without breaking the code.

Thanks

Was it helpful?

Solution

function __construct() 
{
    $this->_app =& JFactory::getApplication();
    parent::__construct();

    // Get pagination request variables
    $limit = $this->_app->getUserStateFromRequest(OPTIOIN_NAME.'.bs.limit', 'limit', $this->_app->getCfg('list_limit'), 'int');
    $limitstart = $this->_app->getUserStateFromRequest(OPTIOIN_NAME.'.bs.limitstart', 'limitstart', 0, 'int');

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

    // Set States
    $this->setState(OPTIOIN_NAME.'.bs.limit', $limit);
    $this->setState(OPTIOIN_NAME.'.bs.limitstart', $limitstart);
}


function pagination()
{
    if($this->_pagination == NULL)
        $this->_pagination = new JPagination(20, $this->getState(OPTIOIN_NAME.'.bs.limitstart'), $this->getState(OPTIOIN_NAME.'.bs.limit'));
    return $this->_pagination;
}

In the constructor get the values and set it to the session. pagination function should be called in the controller.

In the getList or whatever the function you wish to limit the rows

// Set the Limits and Filters
$limit = $this->getState(OPTIOIN_NAME.'.bs.limit');
$limitstart = $this->getState(OPTIOIN_NAME.'.bs.limitstart');

//setup the pagination
$this->_pagination = new JPagination($total, $limitstart, $limit);     

//get the data within limits
$this->_data = $this->_getList($query, $limitstart, $limit);   

//$total is the total number of rows return by the count(*) query.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top