How to create Pagination in Codeiginter?

后端 未结 4 1772
傲寒
傲寒 2020-12-22 03:44

I am new to codeigniter, I am trying to create pagination on the records i am fetching from database. I have written the following code, its showing me pagination but its no

4条回答
  •  鱼传尺愫
    2020-12-22 04:04

    For a better use of pagination create a function in your helper. That will very useful for you for future use. you don't ever need to load library and other values. fix this function in your helper.

    if( ! function_exists('createPaginationForm')) {
        function createPaginationForm($url, $totalRows, $perPage, $segment, $queryString = '', $config = array()) {
            $CI =& get_instance();
            $CI->load->library('pagination');
            $config['base_url'] = base_url().$url;
            $config['total_rows'] = $totalRows;
            $config['per_page'] = $perPage;
            $config['uri_segment'] = $segment;
            $CI->pagination->initialize($config);
            return $CI->pagination->create_links($queryString);
        }
    }
    

    and use in your controller .

    var $perPage = '10';
    var $segment = '4';
    $total_result = "50";
    $pagination = createPaginationForm('admin/news/index/',$total_result ,$this->perPage, $this->segment);
    $this->data['pagination'] = $pagination;
    

    and print this in your view.

    echo $pagination
    

提交回复
热议问题