1

Am using JModelLegacy to get records , everthing works fine . however when setting limit with $model->setState('list.limit', 6); its not limiting the records below is my code :

      $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => false));
      $appParams = JFactory::getApplication()->getParams();
      $model->setState('params', $appParams);
      $model->setState('filter.category_id',$cat_id ); //change that to your Category ID
       $model->setState('list.limit', 6);
      $model->setState('list.ordering', 'hits');
      $model->setState('list.direction', 'ASC');
      $items = $model->getItems();
2
  • List.limit only limits the amount of items per page used by the pagination. If you want to retrieve only 6 records you have to adjust your SQL-Query
    – Mainz007
    Jan 2, 2016 at 15:47
  • if you are adding state variables like that shouldn't you be using: $app = JFactory::getApplication(); $app->setUserState('list.limit',6); Instead of trying to set a state through the model?
    – Terry Carter
    Feb 5, 2016 at 19:09

1 Answer 1

1

I suspect in the context this is being used, you might want to put ignore_request to true?

I believe ContentModelArticles::getItems calls ContentModelArticles::populateState (through ContentModelArticles::getListQuery which in turn call ContentModelArticles::getState) which in turn run the code

$value = $app->input->get('limit', $app->get('list_limit', 0), 'uint');
$this->setState('list.limit', $value);

which sets the limit based on $app->get('list_limit', 0) since 'limit' is likely not passed via request.

1
  • I also think it's the ignore_request. Try $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
    – fruppel
    Mar 2, 2016 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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