dow72046 2013-09-10 14:11
浏览 33
已采纳

joomla 2.5分页始终将起始限制设置为20

I developed my own joomla 2.5 custom component for displaying data table in front-end.It contain filtering,paging and sorting.When navigate via paging it always shows only first 20. Is there any way to override limit of a query which generate on function getListQuery().

My populateState method is

protected function populateState($ordering = null, $direction = null) {
        // Initialise variables.
        $app = JFactory::getApplication();

        $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
        $filter_order = $this->getUserStateFromRequest($this->context . '.filter_order', 'filter_order');
        //$filter_order = JRequest::getCmd('filter_order');
        $filter_order_Dir = $this->getUserStateFromRequest($this->context . '.filter_order_Dir', 'filter_order_Dir');
        //$filter_order_Dir = JRequest::getCmd('filter_order_Dir');

        'filter_region', '');

        $this->setState('filter_order', $filter_order);
        $this->setState('filter_order_Dir', $filter_order_Dir);


        // List state information
        $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
        $this->setState('list.limit', $limit);

        $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
        $this->setState('list.start', $limitstart);

        parent::populateState();
    } 

Constructor method is

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


            //Get configuration
            $app = JFactory::getApplication();
            $config = JFactory::getConfig();

            // Get the pagination request variables
            $this->setState('limit', $app->getUserStateFromRequest('com_jointcm.limit', 'limit', $config->getValue('config.list_limit'), 'int'));
            $this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));
    }

List query method is

protected function getListQuery() {
        // Create a new query object.
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);
 //code goes here...
..............

return $query;
}
  • 写回答

4条回答 默认 最新

  • duanjian4331 2013-09-11 06:01
    关注

    After some digging around and taking a look at the source code of the JModelList class, I realized that problem is with \libraries\joomla\application\component\modellist.php file ,method name public function getItems(),line number 115.

    I changed it to

    public function getItems()
        {
            // Get a storage key.
            $store = $this->getStoreId();
    
            // Try to load the data from internal storage.
            if (isset($this->cache[$store]))
            {
                return $this->cache[$store];
            }
    
            // Load the list items.
            $query = $this->_getListQuery();
            //$items = $this->_getList($query, $this->getStart(), $this->getState('list.limit'));
    $items = $this->_getList($query, $this->getState('limitstart'), $this->getState('list.limit'));
    
            // Check for a database error.
            if ($this->_db->getErrorNum())
            {
                $this->setError($this->_db->getErrorMsg());
                return false;
            }
    
            // Add the items to the internal cache.
            $this->cache[$store] = $items;
    
            return $this->cache[$store];
        }
    

    Change was

    $items = $this->_getList($query, $this->getStart(), $this->getState('list.limit'));
    

    to

    $items = $this->_getList($query, $this->getState('limitstart'), $this->getState('list.limit'));
    

    It works fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题