【问题标题】:joomla pagination getListFooter on front-end not work前端的joomla分页getListFooter不起作用
【发布时间】:2014-06-18 17:05:48
【问题描述】:

我根据http://docs.joomla.org/ 的教程学习开发组件,我在分页时遇到问题,单击第 1、2、3 页...不起作用,

这是我的代码: com_bet/models/test.php:

defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class BetModelTest extends JModelList{      
    protected function getListQuery(){      
        $db=JFactory::getDbo();
        $query=$db->getQuery(true);
        $query->select('*')->from('#__member');     
        return $query;
    }   
}

com_bet/views/test/view.html.php

defined('_JEXEC') or die;
jimport('joomla.application.component.view');
class BetViewTest extends JViewLegacy{
    function display($tpl=null){        
        $items=$this->get('Items');
        $pagination=$this->get('Pagination');
        $this->items=$items;
        $this->pagination=$pagination;
        parent::display($tpl);
    }
}

com_bet/views/test/tmpl/default.php:

defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');
?>
<form action="index.php?option=com_bet&view=test" method="post">
<table>
<thead>
    <tr>
        <th>ID</th>
        <th>Username</th>
        <th>Password</th>
        <th>Funds</th>
    </tr>
</thead>
<tbody> 
    <?php foreach ($this->items as $item){?>
    <tr>
        <td><?php echo $item->id;?></td>
        <td><?php echo $item->username;?></td>
        <td><?php echo $item->pass;?></td>
        <td><?php echo $item->funds;?></td>
    </tr>
    <?php }?>   
</tbody>
<tfoot>
    <tr>
        <td colspan='4'><?php echo $this->pagination->getListFooter();?></td>
    </tr>
<tfoot>
</table>
</form>

我在 chrome 检查元素中观看,它显示“无法读取未定义的属性 'limitstart'”,如后面的图片: http://i1119.photobucket.com/albums/k623/helbros/joomla.png

帮帮我,非常感谢

【问题讨论】:

    标签: joomla pagination


    【解决方案1】:

    您需要在表单中添加id 属性,还需要在表单中使用名称为limitstart 的隐藏字段。目前 javascript 正在寻找 id 为 adminForm 的表单,但找不到它。

    要更新默认限制,您可以通过添加方法 populateState 来扩展您的 Model,它应该如下所示:

    protected function populateState($ordering = null, $direction = null) {
      $app = JFactory::getApplication();
    
      $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'uint');
      $this->setState('list.limit', $limit);
      // As you can see if no limit is set, it gets it from default value of config, 
      // but you can replace $app->getCfg('list_limit') by any integer you want to 
      // override default limit value
    
      $limitstart = $app->input->get('limitstart', 0, 'uint');
      $this->setState('list.start', $limitstart);
    
      $limitstart = $app->input->get('limitstart', 0, 'uint');
      $this->setState('list.start', $limitstart); 
    }
    

    【讨论】:

    • 谢谢你,我添加了 2 个属性 name="adminForm" id="adminForm" 到标签
      现在它可以完美地工作了。但是我还有一个关于在表格上显示记录的问题,它总是在第一次加载网页时显示 20 条记录,如何更改。有人说在代码中更改 $limit 值,但我不知道在哪里更改.
    【解决方案2】:

    这是一个老问题(一年多以前),但我在 Joomla 3 上遇到了同样的问题——也就是说,我可以通过一些努力让分页在前端工作,但改变了显示的列表元素不起作用。我终于弄明白了。

    问题是过滤器和分页中的选择限制框的名称都是“limit”而不是“list[limit]”。将 HTML 编辑为后者使其工作。

    如何使它在代码中工作: 1. 你必须有一个过滤器,所以 /models/form 中有一个 filter_VIEW.xml 文件,其中包含一个字段列表“list”和一个字段“limit”,类型为“limitbox”(以 com_users 为例)。 2.您必须在视图中调用过滤器

    JLayoutHelper::render('joomla.searchtools.default', array('view' => $this, 'options' => array('filtersHidden' =>$hidden)));
    

    这将在过滤器区域中为您提供一个限制框(您不需要任何其他过滤器)。 3.为了去掉分页区域的不工作的限制框,使用CSS将类“limit”设置为“display:none;”

    我希望这对其他人有所帮助。我花了很长时间才弄清楚这一点。

    【讨论】:

      猜你喜欢
      • 2013-08-10
      • 1970-01-01
      • 2012-01-31
      • 2013-02-25
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      相关资源
      最近更新 更多