使用codeigniter分页

时间:2016-10-12 11:11:11

标签: php codeigniter pagination

分页不适用于我的项目并且没有显示任何内容(没有分页 - 1,2,3,......我从数据库中获得完整的结果)。

我的控制器:

public function list_result()
{

    $this->run_cache();
    $this->initialize_limit();
    $limit = (is_int($this->uri->segment(2)))?$this->uri->segment(2):0;
    $offset = $this->result_limit;
    $query = "SELECT title,user_photo,id,created_date
              FROM result";
    $query .= " LEFT JOIN users ON result.user_id = users.user_id ";

    if ($this->uri->segment(2) == 'popular') {
        $this->session->set_userdata('filterQuery', " ORDER BY result.id DESC ");
    }
    $query .= " WHERE state = 1";
    $query .= $this->filter_query();

    if (!$this->session->userdata('filterQuery')) {
        $query .= " ORDER BY created_date DESC ";
    }
    $query .= " LIMIT " . $limit . "," . $offset;
    $grow['result'] = $this->db->query($query)->result();

    $this->load->library('pagination');
    $config['base_url'] = base_url() . "site";
    $config['total_rows'] = count($grow['result']);
    $config['per_page'] = $this->result_limit;
    $config['uri_segment'] = 2;
    $config['full_tag_open'] = '<ul class="uk-pagination">';
    $config['full_tag_close'] = '</ul>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="uk-active"><span>';
    $config['cur_tag_close'] = '</span></li>';
    $config['use_page_numbers'] = TRUE;
    $this->pagination->initialize($config);
    $grow['links'] = $this->pagination->create_links();

    $grow['site'] = $this;
    $this->load->view('share/list_result', $grow);
}

我的观点:

<?php 
if (count($result) > 0) {
    ?>
    <?php
    foreach ($result as $row) {
        ?>
        show results here
        <?php 
    }
    ?>
    <p><?php echo $links; ?></p> <!-- Nothing shown here -->
<?php } else { ?>

            No Result Found
<?php
}
?>

你能帮我找一下我在哪里弄错了吗?

1 个答案:

答案 0 :(得分:0)

这里我是如何处理以解决问题的。 对于有相同问题并用Google搜索的用户。

我改变了:

$limit = (is_int($this->uri->segment(2)))?$this->uri->segment(2):0;

$limit = (is_numeric($this->uri->segment(2)))?($this->uri->segment(2) - 1):0;