Welcome Guest, Not a member yet? Register   Sign In
How to make paging from the basics
#2

1. I put default pagination configs in application/config/pagination.php :
PHP Code:
<?php if (!defined('BASEPATH'))
exit(
'No direct script access allowed');

$config['per_page'] = 10;
$config['num_links'] = 3;
$config['page_query_string'] = TRUE;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = "</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$config['last_link'] = 'first';
$config['first_link'] = 'last'

2. In controller 

PHP Code:
class Post extends CI_Controller{

 
   public function __construct() {
 
       parent::__construct();
 
   }

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

        $offset 0;
        
//per_page is the variable of pagination library, if you want you can change this variable name in pagination configs
        if ($this->input->get('per_page') != null) {
            $offset $this->input->get('per_page');
        }
        $count 10//number of posts in page 
       
filter = array();
        $data['post_count'] = $this->post_model->get_total_post_count($filter); //pagination need to know how many total posts you have 

        $data['posts'] = $this->post_model->get_posts($filter$limit$offset);
        
        $config
['base_url'] = site_url() . 'post/all_posts';
        $config['total_rows'] = $data['post_count'];
        $config['per_page'] = $count;

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

        $data['pagination'] = $this->pagination->create_links();

        $this->load->view('templates/header'$data);
    
    


in view: 
PHP Code:
<?php echo $pagination//to show pagination links; ?>
Reply


Messages In This Thread
RE: How to make paging from the basics - by neuron - 08-10-2017, 02:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB