class ExampleModel extends JModelList { protected function populateState($ordering = null, $direction = null) { // Set the limit to retrieve only 10 articles. $this->setState('list.limit', 10); // Set the ordering to retrieve the articles by the publish date in descending order. $this->setState('list.ordering', 'publish_up'); $this->setState('list.direction', 'desc'); parent::populateState($ordering, $direction); } public function getListQuery() { // Build the query to retrieve the articles. $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*') ->from('#__content') ->where('state = 1'); return $query; } }
class ExampleModel extends JModelList { protected function populateState($ordering = null, $direction = null) { // Set the filter to retrieve only users with the user group of 2. $this->setState('filter.group_id', 2); // Set the search parameter to filter the users by their email address. $this->setState('list.search', 'example@example.com'); parent::populateState($ordering, $direction); } public function getListQuery() { // Build the query to retrieve the users. $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*') ->from('#__users') ->where('block = 0'); // Add the filter for the user group. $filterGroupId = $this->getState('filter.group_id'); if (!empty($filterGroupId)) { $query->where('group_id = '.(int) $filterGroupId); } // Add the search filter for the email address. $search = $this->getState('list.search', ''); if (!empty($search)) { $search = $db->Quote('%'.$db->escape($search, true).'%'); $query->where('(email LIKE '.$search.')'); } return $query; } }These examples use the JModelList class from the Joomla\Legacy\Model namespace, which is part of the Joomla CMS package library.