Welcome Guest, Not a member yet? Register   Sign In
Pagination config file not loading [Solved]
#1

[eluser]Adrian Walls[/eluser]
Hi,

I have sucessfully added pagination to my application and I wanted to start to use css to style the pagination links. As this will be used in more than one place I want to put pagination configuration options into a config file so its available application wide. I have created my config/pagination.php file which looks like:

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

//$config['full_tag_open'] = '<p>';
//$config['full_tag_close'] = '</p>';

// First Links
$config['first_link'] = 'First Link';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';

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

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

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

// Current Link
$config['cur_tag_open'] = '<li class="active">';
$config['cur_tag_close'] = '</li>';

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

/* End of file pagination.php */
/* Location: ./system/application/config/pagination.php */

and my controller looks like (NOTE: I am using Smarty for my view):

Code:
//Load models
$this->load->model('stock_model');

//Load libraries
$this->load->library('pagination');
        
//get total stock
$query_rows = $this->stock_model->get_stock_count();
        
//Setup pagination options
$limit = $this->config->item('stock_listings_per_page');
$stock_list = $this->stock_model->get_stock_list($limit, $offset);
                
$config['base_url'] = $this->config->item('base_url')."/index.php/admin/list_stock/";
$config['total_rows'] = $query_rows;
$config['per_page'] = $limit;
                    
$this->mysmarty->assign("paginateLinks", $this->pagination->create_links());            
$this->mysmarty->assign("stockList", $stock_list);

However when I use this as above the pagination links are not being created. The Pagination user manual page says that if you are using a config file then you do NOT need to initialize this using

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

as its automatically loaded for you. However my pagination links do not appear at all if I don't include this initialize in my controller.

Any ideas? All help greatly appriciated.
#2

[eluser]Vi.[/eluser]
Try to track your mysql result. $query_rows may be smaller than $limit or equal to NULL.

Code:
echo $this->db->last_query(); // after mysql_query || db->get()

Code:
print_r($config); // after pagination config
#3

[eluser]Adrian Walls[/eluser]
Quote:
Code:
echo $this->db->last_query(); // after mysql_query || db->get()
SELECT * FROM (`stock`) WHERE `deleted` = 0 ORDER BY `make` asc, `model` asc LIMIT 2, 1


Quote:
Code:
print_r($config); // after pagination config
Array ( [base_url] => http://localhost/dev/cleonard/index.php/...ist_stock/ [total_rows] => 5 [per_page] => 1 )

Also just an observation a colleague has tried this in one of his projects using CI v1.7.0 and it works as expected. I am using CI 1.7.2.
#4

[eluser]Vi.[/eluser]
Your CSS code is working after including "$this->pagination->initialize($config);" ?

Try to add this code to load pagination config file. As I see, config/pagination.php isn't included.

Code:
$this->load->config('pagination')
#5

[eluser]Adrian Walls[/eluser]
To make sure there are no css issues I have striped my config/pagination.php to just:

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['first_link'] = 'My Start Link';

However its still not picking this up. The documentation also says that this is loaded automatically however I cannot see from the code how this actually happens. As I mentioned this is working OK for a colleague using 1.7.0 however he must use the line:

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

even though the user guide says you do not need to use the initialize function if you are using the config file.

I am not sure if this is directly related to my issue but on the surface it would appear in having to call the initialize function there is a error in the user manual or a bug in CI.
#6

[eluser]Vi.[/eluser]
I figure it out now. This feature didn't explained well in User Guide.
You must write your pagination config into config/pagination.php

Example;
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//$config['full_tag_open'] = '<p>';
//$config['full_tag_close'] = '</p>';

// First Links
$config['first_link'] = 'First Link';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';

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

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

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

// Current Link
$config['cur_tag_open'] = '<li class="active">';
$config['cur_tag_close'] = '</li>';

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

// Paginatio config                
$config['base_url'] = $this->config->item('base_url')."/index.php/admin/list_stock/";
$config['total_rows'] = 100;
$config['per_page'] = 10;

/* End of file pagination.php */
/* Location: ./system/application/config/pagination.php */

Controllers;
Code:
//Load models
$this->load->model('stock_model');

//Load libraries
$this->load->library('pagination');

//get total stock
$query_rows = $this->stock_model->get_stock_count();

$this->mysmarty->assign("paginateLinks", $this->pagination->create_links());            
$this->mysmarty->assign("stockList", $stock_list);


It worked in my project (1.7.2).
#7

[eluser]Adrian Walls[/eluser]
Found out what the problem was. My own stupid fault. I had expanded the Pagination library with MY_Pagination as I wanted to investigate setting up pagination links with "1-10, 11-20, 21-30 etc" style links. I quickly decided against this. However I forgot to remove MY_Pagination.php. This was causing the pagination config file not to get loaded.

Anyway all working as expected. Thanks for your time and efforts Vi. and anyone else for looking into this. Sorry for wasting your time.
#8

[eluser]Vi.[/eluser]
I'm glad you already solved your problems (:




Theme © iAndrew 2016 - Forum software by © MyBB