Codeigniter分页$ this-> pagination-> create_links()

时间:2014-07-28 09:24:07

标签: php codeigniter pagination

我遇到了问题。 $this->pagination->create_links()返回null字符串。

这是模特:

class Pagination_m extends CI_Model {

public function PaginationHome($count)
{
    $this->load->library('pagination');

    $config['base_url'] = base_url().'home';
    $config['total_rows'] = ceil($count/12);
    $config['per_page'] = 5;
    $config['uri_segment'] = 2;
    $config['full_tag_open'] = '<div style="float: left; width: 960px;">';
    $config['full_tag_close'] = '</div>';
    $this->pagination->initialize($config);
}

}

控制器:

$count = count($this->pictures_m->getAll());

    $this->load->model('pagination_m');
    $this->pagination_m->PaginationHome($count);
    $data['links'] = $this->pagination->create_links();
    var_dump($data['links']);

$count返回15,

谢谢!

1 个答案:

答案 0 :(得分:1)

将您的分页配置保留在控制器中: -

    $this->load->library('pagination'); 
    $per_page = 50; 
    $data['result'] = $this->model->function_name(); // for display result
    $config['total_rows'] = $this->model->function_name(); // or count rows
    $config['per_page']= $per_page;
    $config['uri_segment'] = 3;
    $config['base_url']= base_url().'/index'; // your url
    $config['suffix'] = '?'.http_build_query($_GET, '', "&"); 
    $this->pagination->initialize($config);
    $data['paginglinks'] = $this->pagination->create_links();   
    $this->load->view('viewname', $data); //your view name

型号: -

   write function which return bunch of data and count rows

查看(显示您的数据): -

     <?php echo $paginglinks; ?>

更多信息: - http://ellislab.com/codeigniter/user-guide/libraries/pagination.html