0
    $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 -> 将记录数设置为 10,当我转到 PAGES 2 -> 分页自动设置为 10。我想为不同的页面设置不同的分页设置。

它的作用是,它保留一个全局变量。所以即使我移动到另一个页面,这些分页设置也会被保存和应用。如果我改变OPTIOIN_NAME.'.limitstart'或改变'global.list.limit'它给我的其他东西Warning: Attempt to assign property of non-object in D:\wamp\www\jink\libraries\joomla\registry\registry.php on line 342。我怎样才能在不破坏代码的情况下解决这个问题。

谢谢

4

1 回答 1

0
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;
}

在构造函数中获取值并将其设置为会话。应该在控制器中调用分页函数。

在 getList 或您希望限制行的任何函数中

// 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.
于 2012-10-11T12:42:12.467 回答