Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter 3 pagination class with bootstrap 4

Is Codeigniter 3 compatible with Bootstrap 4? or is it simply way too outdated to add any uses for bootstrap 4?

I've been looking at tutorials online on how to integrate bootstrap to Codeigniter pagination.

So far all i've seen is that they mostly changed the $config of the pagination class. For example:

//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';

I wanted a clear divide in my codes. Simply, I wanted less PHP in my HTML and more HTML there.

This is the Pagination code snippet in w3school bootstrap 4 tutorial.

<ul class="pagination">
  <li class="page-item"><a class="page-link" href="#">Previous</a></li>
  <li class="page-item"><a class="page-link" href="#">1</a></li>
  <li class="page-item"><a class="page-link" href="#">2</a></li>
  <li class="page-item"><a class="page-link" href="#">3</a></li>
  <li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>

How do I integrate the above code to my pagination class?

Do I have to do it the way the above tutorial did? or can I simply use a foreach loop in my HTML/view page to create the links depending on the records from the database?

like image 934
Chief Makii Avatar asked Dec 16 '17 13:12

Chief Makii


4 Answers

The best. You have tried many, but this one is the one that best fit the page.

// Bootstrap 4, work very fine.
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['attributes'] = ['class' => 'page-link'];
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li class="page-item">';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="page-item">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li class="page-item">';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li class="page-item">';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a href="#" class="page-link">';
$config['cur_tag_close'] = '<span class="sr-only">(current)</span></a></li>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
like image 180
Rodrigo Prazim Avatar answered Nov 13 '22 09:11

Rodrigo Prazim


The code you added belongs to Bootstrap-3. Try this

$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li class="page-item">';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="page-item prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<liclass="page-item">';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<liclass="page-item">';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a class="page-link">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
like image 20
Abdulla Nilam Avatar answered Nov 13 '22 09:11

Abdulla Nilam


This works for me

    // Bootstrap 4 Pagination fix
    $config['full_tag_open']    = '<div class="pagging text-center"><nav><ul class="pagination">';
    $config['full_tag_close']   = '</ul></nav></div>';
    $config['num_tag_open']     = '<li class="page-item"><span class="page-link">';
    $config['num_tag_close']    = '</span></li>';
    $config['cur_tag_open']     = '<li class="page-item active"><span class="page-link">';
    $config['cur_tag_close']    = '<span class="sr-only">(current)</span></span></li>';
    $config['next_tag_open']    = '<li class="page-item"><span class="page-link">';
    $config['next_tag_close']  = '<span aria-hidden="true"></span></span></li>';
    // $config['next_tag_close']  = '<span aria-hidden="true">&raquo;</span></span></li>';
    $config['prev_tag_open']    = '<li class="page-item"><span class="page-link">';
    $config['prev_tag_close']  = '</span></li>';
    $config['first_tag_open']   = '<li class="page-item"><span class="page-link">';
    $config['first_tag_close'] = '</span></li>';
    $config['last_tag_open']    = '<li class="page-item"><span class="page-link">';
    $config['last_tag_close']  = '</span></li>';
like image 2
Orion Avatar answered Nov 13 '22 09:11

Orion


Best solution

$config['full_tag_open']    = '<nav aria-label="Page navigation"><ul class="pagination">';
$config['full_tag_close']   = '</ul></nav>';
$config['num_tag_open']     = '<li class="page-item">';
$config['num_tag_close']    = '</li>';
$config['cur_tag_open']     = '<li class="page-item active"><span class="page-link">';
$config['cur_tag_close']    = '</span></li>';
$config['next_tag_open']    = '<li class="page-item">';
$config['next_tag_close']  = '</li>';
$config['prev_tag_open']    = '<li class="page-item">';
$config['prev_tag_close']  = '</li>';
$config['first_tag_open']   = '<li class="page-item">';
$config['first_tag_close'] = '</li>';
$config['last_tag_open']    = '<li class="page-item">';
$config['last_tag_close']  = '</li>';

then Add page-link class to a tag via jquery

    jquery('.page-item>a').addClass("page-link");
like image 2
Mon Mohon Singha Avatar answered Nov 13 '22 09:11

Mon Mohon Singha