Welcome Guest, Not a member yet? Register   Sign In
Using initialize() in pagination with an external configuration
#1

Hi, in the pagination docs it says

Quote:You will NOT need to use $this->pagination->initialize() if you save your preferences in a config file.

I have made this file and have a bunch of configurations there, but if I leave the initialize part out of my controller, the pagination links don't show at all. It's not a big deal because it works when I add it, but I was curious know what the docs meant by this.

Here is my code

Controller

 
PHP Code:
public function read($pagination_offset 0)
   {
     $this->load->library('pagination');
     $pagination_config['base_url'] = base_url().'/language/read/'
     $pagination_config['per_page'] = 20

     $this->data['languages'] = $this->language_model->get_languages($pagination_config['per_page'], $pagination_offset); 
     $total_query_rows $this->db->query('SELECT id FROM languages')->num_rows(); 

     $pagination_config['total_rows'] = $total_query_rows;
     $this->pagination->initialize($pagination_config); 

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

Model

PHP Code:
   public function get_languages($limit$pagination_offset)
   {
     $query $this->db->query("
     SELECT
      languages.id AS id,
       languages.title AS language,
       country_code,
      COUNT(courses.id) AS number_of_courses
     FROM languages
     LEFT JOIN courses
     ON languages.id = courses.language_id
     GROUP BY languages.title
     LIMIT 
$limit OFFSET $pagination_offset
     "
);
     $languages $query->result();
     return $languages;
   
/config/pagination.php

PHP Code:
   <?php
   defined
('BASEPATH') OR exit('No direct script access allowed');

   $config['full_tag_open'] = '<ul class="w3-pagination w3-border w3-light-grey">';
   $config['full_tag_close'] = '</ul>';

   $config['first_link'] = 'First'// might require more than 5 pages by default to show up
   $config['first_tag_open'] = '<li>';
   $config['first_tag_close'] = '</li>';
   // $config['first_url'] = ''; // An alternative URL to use for the “first page” link.

   $config['last_link'] = 'Last';
   $config['last_tag_open'] = '<li>';
   $config['last_tag_close'] = '</li>';

   $config['next_link'] = '&raquo;';
   $config['next_tag_open'] = '<li>';
   $config['next_tag_close'] = '</li>';

   $config['prev_link'] = '&laquo;';
   $config['prev_tag_open'] = '<li>';
   $config['prev_tag_close'] = '</li>';

   $config['cur_tag_open'] = '<li><b><a class="w3-green" href="#">';
   $config['cur_tag_close'] = '</a></b></li>';

   $config['num_tag_open'] = '<li>';
   $config['num_tag_close'] = '</li>'

View

PHP Code:
   <?php if (!empty($pagination)): ?>
     <div class="w3-container">
       <div class="w3-card-2 w3-padding w3-light-grey">
         <?php echo $pagination?>
       </div>
     </div>
   <?php endif; ?>

Thanks Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB