无法创建链接分页codeigniter

时间:2013-11-05 15:59:59

标签: php codeigniter pagination

无法在codeigniter中创建链接分页。 代码:

$config['total_rows'] = $tot_hal->num_rows();
        $config['per_page'] = $limit;
        $config['uri_segment'] = 3;
        $config['first_link'] = 'Awal';
        $config['last_link'] = 'Akhir';
        $config['next_link'] = 'Selanjutnya';
        $config['prev_link'] = 'Sebelumnya';
        $this->pagination->initialize($config);
        $bc["paginator"] =$this->pagination->create_links();

它接下来不能分页,很明显。可能是什么原因?

2 个答案:

答案 0 :(得分:0)

请试试这个:

        $page = ($this->uri->rsegment(3)) ? $this->uri->rsegment(3) : 0;
        $user_data['total_users'] = $total_counting; // set total number of records
        $user_data['pagination'] = $this->pagination->create_links(); // set pagination
        $user_data['page_limit'] = $lim; // set limit for pagination           
        $user_data['all_users'] = $this->User_model->get_user_list($lim, $page); // Function call from model      

        $this->template->load('template', 'users/list_user',$user_data); 

在User_model.php文件中

 public function get_user_list($limit=0,$offset=0,$condition='',$fields='*')
{
    $this->db->select($fields);
    if(isset($limit)&& $limit!='')
    {
        $this->db->limit($limit, $offset);
    }
    $this->db->from(USER_TABLE_NAME);
    if(isset($condition) && $condition != '')
    {
        $this->db->where($condition);
    }
    $this->db->order_by("firstname", "asc"); 
    $query = $this->db->get();
    echo $this->db->last_query(); // Get Last Query
    return $query->result_array();
}

在视图文件

      if(isset($all_users)){
        if(isset($pagination))
        echo $pagination;
        }

答案 1 :(得分:0)

尝试在视图页面中使用创建链接功能,只显示不在控制器中的分页链接。

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