2

20150203 - Title changed from 'JModelLegacy returns 0 items when setting limit 0 and limitstart > 0' because title did not fit anymore.

I am developing a component and after debugging a while I found a very strange phenomenon.

In my frontend you can set a pagination limit to see a defined limit of items. Everything looks fine at the first sight.

Under several circumstances I got back zero items. Thats why I started debugging the code.

In the Legacy Model of Joomla \libraries\legacy\model\legacy.php there is a function _getList($query, $limitstart = 0, $limit = 0), which is responsible for initiating the query and returning the results. And here is my problem:

If $limitstart has a value > 0 and $limit = 0, then no items will be returned. This problem arises when you switch with the pagination to the last site. The limit will be set to 0, because there is no limit any more. Only the last results should be shown, eg. $startlimit = 15 and $total = 18, but the mentioned function returns 0.

What's wrong here? Can anybody help?

  • 20150203 - Title changed from 'JModelLegacy returns 0 items when setting limit 0 and limitstart > 0' because title did not fit anymore. Last valid entry see comment to Valentin Despas answer. – Perino Feb 3 '15 at 15:29
1

The limit will be set to 0, because there is no limit any more. - FALSE!

$limit should never be 0. Limit is the maximum number of records to be returned, so it cannot be 0. If you keep browsing through pages, the limit won't change, even for the last page.

Probably you have something misconfigured or you are setting it on purpose to 0.

I am making some assumptions here and I am guessing what could the issue be. As you cannot directly use the Legacy class, I assume you are actually using / inheriting from JModelList calling the method getItems().

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

As you can see, there is a call to a state variable:

$this->getState('list.limit')

Check that this state variable is set and have a value different from null or 0.

Hope this helps.

  • The problem seems to get clearer. I do a manual override of the pagination in the model. This will be done by the function 'getPagination'. To get the values of the form I do eg. $limit = JRequest::getVar('limit', 0 , '', 'int'). When I set the pagination limit in the frontend to eg 5, then $limit = 5 and will work. When I switch in the frontend with the pagination to the next site, the $limit will be 0 (the frontend Pagination Limit shows ALL) and my problem come up: limitstart = 5 and listlimit = 0. – Perino Feb 2 '15 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.