2014-03-07 80 views
0

我有超过5个结果的文章页面。每页显示5个结果。分页显示。然而,当我转到不同的页面时,每个页面都有相同的5个结果。joomla分页在每一页上显示相同的结果

我getItems():

function getItems() 
{ 

    $params = $this->getState()->get('params'); 
    $limit = $this->getState('list.limit'); 
    // 5 

    if ($this->_articles === null && $category = $this->getCategory()) { 
     $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); 
     $model->setState('params', JFactory::getApplication()->getParams()); 
     $model->setState('filter.category_id', $category->id); 
     $model->setState('filter.published', $this->getState('filter.published')); 
     $model->setState('filter.access', $this->getState('filter.access')); 
     $model->setState('filter.language', $this->getState('filter.language')); 
     $model->setState('list.ordering', $this->_buildContentOrderBy()); 
     $model->setState('list.start', $this->getState('list.start')); 
     $model->setState('list.limit', $limit); 

     $model->setState('list.direction', $this->getState('list.direction')); 
     $model->setState('list.filter', $this->getState('list.filter')); 
     // filter.subcategories indicates whether to include articles from subcategories in the list or blog 
     $model->setState('filter.subcategories', $this->getState('filter.subcategories')); 
     $model->setState('filter.max_category_levels', $this->setState('filter.max_category_levels')); 
     $model->setState('list.links', $this->getState('list.links')); 


     if ($limit >= 0) { 
      $this->_articles = $model->getItems(); 
      if ($this->_articles === false) { 
       $this->setError($model->getError()); 
      } 
     } 
     else { 
      $this->_articles=array(); 
     } 

     $this->_pagination = $model->getPagination(); 
    } 
    $filterResult = null; 


    return $this->_articles; 
} 

我填入状态:

protected function populateState($ordering = null, $direction = null) 
    { 
     // Initiliase variables. 
     $app = JFactory::getApplication('site'); 
     $pk  = JRequest::getInt('id'); 

     $this->setState('category.id', $pk); 

     // Load the parameters. Merge Global and Menu Item params into new object 
     $params = $app->getParams(); 
     $menuParams = new JRegistry; 

     if ($menu = $app->getMenu()->getActive()) { 
      $menuParams->loadString($menu->params); 
     } 

     $mergedParams = clone $menuParams; 
     $mergedParams->merge($params); 

     $this->setState('params', $mergedParams); 
     $user  = JFactory::getUser(); 
       // Create a new query object. 
     $db  = $this->getDbo(); 
     $query = $db->getQuery(true); 
     $groups = implode(',', $user->getAuthorisedViewLevels()); 

     if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))){ 
      // limit to published for people who can't edit or edit.state. 
      $this->setState('filter.published', 1); 

      /** 
      * Custom Author Filter 
      */ 
      if (JRequest::getVar('author')) { 
       $this->setState('filter.created_by', $this->getUserId(JRequest::getVar('author'))); 
      } 

      // Filter by start and end dates. 
      $nullDate = $db->Quote($db->getNullDate()); 
      $nowDate = $db->Quote(JFactory::getDate()->toMySQL()); 

      $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); 
      $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); 

      /** 
      * Custom Author Filter 
      */ 
      if (JRequest::getVar('author')) { 
       $query->where('(a.created_by = "' . $this->getUserId(JRequest::getVar('author')) . '")'); 
      } 
     } 


     // process show_noauth parameter 
     if (!$params->get('show_noauth')) { 
      $this->setState('filter.access', true); 
     } 
     else { 
      $this->setState('filter.access', false); 
     } 

     // Optional filter text 
     $this->setState('list.filter', JRequest::getString('filter-search')); 

     // filter.order 
     $itemid = JRequest::getInt('id', 0) . ':' . JRequest::getInt('Itemid', 0); 
     $orderCol = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order', 'filter_order', '', 'string'); 
     if (!in_array($orderCol, $this->filter_fields)) { 
      $orderCol = 'a.ordering'; 
     } 
     $this->setState('list.ordering', $orderCol); 

     $listOrder = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order_Dir', 
      'filter_order_Dir', '', 'cmd'); 
     if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { 
      $listOrder = 'ASC'; 
     } 
     $this->setState('list.direction', $listOrder); 

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

     // set limit for query. If list, use parameter. If blog, add blog parameters for limit. 
     if ((JRequest::getCmd('layout') == 'blog') || $params->get('layout_type') == 'blog') { 
      $limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links'); 
      $this->setState('list.links', $params->get('num_links')); 
     } 
     else { 
      $limit = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.limit', 'limit', $params->get('display_num')); 
     } 

     $this->setState('list.limit', $limit); 

     // set the depth of the category query based on parameter 
     $showSubcategories = $params->get('show_subcategory_content', '0'); 

     if ($showSubcategories) { 
      $this->setState('filter.max_category_levels', $params->get('show_subcategory_content', '1')); 
      $this->setState('filter.subcategories', true); 
     } 



     $this->setState('filter.language',$app->getLanguageFilter()); 

     $this->setState('layout', JRequest::getCmd('layout')); 

    } 

我的显示功能去view.html.php

function display($tpl = null) 
    { 
     $app = JFactory::getApplication(); 
     $user = JFactory::getUser(); 

     // Get some data from the models 
     $state  = $this->get('State'); 

     $params  = $state->params; 
     $items  = $this->get('Items'); 

     $contactId = JRequest::getVar('author'); 
     if($contactId){ 
      $this->setUserId($contactId); 
      $this->setContactName($this->userId); 
     } 

     $category = $this->get('Category'); 
     $children = $this->get('Children'); 
     $parent  = $this->get('Parent'); 
     $pagination = $this->get('Pagination'); 


     // Check for errors. 
     if (count($errors = $this->get('Errors'))) { 
      JError::raiseError(500, implode("\n", $errors)); 
      return false; 
     } 

     if ($category == false) { 
      return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); 
     } 

     if ($parent == false) { 
      return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); 
     } 

     // Setup the category parameters. 
     $cparams = $category->getParams(); 
     $category->params = clone($params); 
     $category->params->merge($cparams); 

     // Check whether category access level allows access. 
     $user = JFactory::getUser(); 
     $groups = $user->getAuthorisedViewLevels(); 
     if (!in_array($category->access, $groups)) { 
      return JError::raiseError(403, JText::_("JERROR_ALERTNOAUTHOR")); 
     } 

     // PREPARE THE DATA 
     // Get the metrics for the structural page layout. 
     $numLeading = $params->def('num_leading_articles', 1); 
     $numIntro = $params->def('num_intro_articles', 4); 
     $numLinks = $params->def('num_links', 4); 

     // Compute the article slugs and prepare introtext (runs content plugins). 

     for ($i = 0, $n = count($items); $i < $n; $i++) 
     { 
      $item = &$items[$i]; 
      $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; 

      // No link for ROOT category 
      if ($item->parent_alias == 'root') { 
       $item->parent_slug = null; 
      } 

      $item->event = new stdClass(); 

      $dispatcher = JDispatcher::getInstance(); 

      // Ignore content plugins on links. 
      if ($i < $numLeading + $numIntro) { 
       $item->introtext = JHtml::_('content.prepare', $item->introtext); 

       $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$item->params, 0)); 
       $item->event->afterDisplayTitle = trim(implode("\n", $results)); 

       $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$item->params, 0)); 
       $item->event->beforeDisplayContent = trim(implode("\n", $results)); 

       $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$item->params, 0)); 
       $item->event->afterDisplayContent = trim(implode("\n", $results)); 
      } 
     } 

     // Check for layout override only if this is not the active menu item 
     // If it is the active menu item, then the view and category id will match 

     $active = $app->getMenu()->getActive(); 

     if ((!$active) || ((strpos($active->link, 'view=category') === false) || (strpos($active->link, '&id=' . (string) $category->id) === false))) { 
      // Get the layout from the merged category params 
      if ($layout = $category->params->get('category_layout')) { 
       $this->setLayout($layout); 
      } 
     } 
     // At this point, we are in a menu item, so we don't override the layout 
     elseif (isset($active->query['layout'])) { 
      // We need to set the layout from the query in case this is an alternative menu item (with an alternative layout) 
      $this->setLayout($active->query['layout']); 
     } 

     // For blog layouts, preprocess the breakdown of leading, intro and linked articles. 
     // This makes it much easier for the designer to just interrogate the arrays. 
     if (($params->get('layout_type') == 'blog') || ($this->getLayout() == 'blog')) { 
      $max = count($items); 

      // The first group is the leading articles. 
      $limit = $numLeading; 
      for ($i = 0; $i < $limit && $i < $max; $i++) { 
       $this->lead_items[$i] = &$items[$i]; 
      } 

      // The second group is the intro articles. 
      $limit = $numLeading + $numIntro; 
      // Order articles across, then down (or single column mode) 
      for ($i = $numLeading; $i < $limit && $i < $max; $i++) { 
       $this->intro_items[$i] = &$items[$i]; 
      } 

      $this->columns = max(1, $params->def('num_columns', 1)); 
      $order = $params->def('multi_column_order', 1); 

      if ($order == 0 && $this->columns > 1) { 
       // call order down helper 
       $this->intro_items = ContentHelperQuery::orderDownColumns($this->intro_items, $this->columns); 
      } 

      $limit = $numLeading + $numIntro + $numLinks; 
      // The remainder are the links. 
      for ($i = $numLeading + $numIntro; $i < $limit && $i < $max;$i++) 
      { 
        $this->link_items[$i] = &$items[$i]; 
      } 
     } 

     $children = array($category->id => $children); 

     //Escape strings for HTML output 
     $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); 


     $this->assign('maxLevel', $params->get('maxLevel', -1)); 
     $this->assignRef('state', $state); 
     $this->assignRef('items', $items); 
     $this->assignRef('category', $category); 
     $this->assignRef('children', $children); 
     $this->assignRef('params', $params); 
     $this->assignRef('parent', $parent); 
     $this->assignRef('pagination', $pagination); 
     $this->assignRef('user', $user); 
     $this->_prepareDocument(); 
     parent::display($tpl); 
    } 

如果我打印$的内容分页在view.html.php这里:

$this->_prepareDocument(); 

     echo '<pre>'; print_r($pagination); exit(); 
     parent::display($tpl); 

我得到如下结果:

在我的模板文件,我赞同分页:

<?php echo $this->pagination->getPagesLinks(); ?> 

顺便说一句,点击“下一步”并更改URL到...?start=5

+0

做一个''==向'$类= $这个 - > getCategory()'也可以发布你的'getListQuery()'? – ilias

+0

您正在扩展哪个核心Joomla模型类? JModelList? –

回答

0

这条线populateState被注释掉

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

取消它改变它TOT获得 “开始” 参数:

$this->setState('list.start', JRequest::getVar('start', 0, '', 'int')); 
相关问题