【问题标题】:Setting pagination设置分页
【发布时间】:2017-05-11 11:49:51
【问题描述】:

控制器/home.php

$this->page_model->counter($this->data['post_detail']->post_ID);
        $this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID);
        $this->data['gallery_list'] = $this->post_model->post($this->data['post_detail']->post_ID, true);       





        $isAjax = array('news-post');
        if (in_array($this->data['post_detail']->template_name, $isAjax))
        {
            if ( ! $this->input->is_ajax_request())
                redirect($this->data['page_detail']->post_alias);

            return $this->load->view($this->data['post_detail']->template_name, $this->data);
        }
        $this->load->view($this->data['post_detail']->template_name, $this->data);

views/news.php

<?php 
        $this->load->library('pagination');

        $config['base_url'] = 'http://gsa-constructionspecialist.com/articles/article';
        $config['total_rows'] = 14;
        $config['per_page'] = 5;

        $this->pagination->initialize($config);

        ?>

    <div class="w626 content right">
        <?php
        if ($post_list){
        foreach ($post_list as $pl){
        ?>
        <div>
            <p><br><br><strong><?php echo $pl->post_title; ?></strong></p>
            <p><?php echo date('F jS, Y',strtotime($pl->post_date)); ?></p>
            <br/>
            <div style="text-align:justify"><?php echo word_limiter(strip_tags($pl->post_content),25); ?><a href="<?php echo site_url('articles/'.$this->uri->segment(2).'/detail/'.$pl->post_alias); ?>"><span style="color:#fff">&nbsp;&nbsp;Read More ></span></a></div>
        </div>
        <?php } } ?>

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

我正在尝试设置分页,但它只显示在底部,它不会隐藏假设在下一页上的文章。

请帮助修复代码?提前致谢。

【问题讨论】:

    标签: codeigniter pagination


    【解决方案1】:

    分页类将根据您提供给它的信息生成页码,但您可以为特定页面生成实际结果。您可能会告诉分页类它每页 5 个结果,但实际上它不知道您是每页输出 5 个结果还是 500 个。

    在我看来:

    $this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID);
    

    需要当前页码传入,即

    $this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID, $current_page);
    

    然后您需要使用 LIMIT 修改模型中的数据库查询,以限制该页面的结果数量(和偏移量)。

    这有帮助吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-27
      • 2019-07-11
      • 1970-01-01
      • 2013-12-23
      • 2020-04-01
      • 2015-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多