views:

89

answers:

2

Hello all

I am trying to implement pagination in my CI webapp. Now I put the config for pagination inside a config file like this...

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['base_url'] = "http://example.com/index.php/home/index";
$config['num_links'] = "9";
$config['per_page'] = "20";
$config['total_rows'] = "200";

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

In my controller, I have loaded the library

$this->load->library("pagination");

And I have defined the pagination config file to be autoload in config/autoload.php

$autoload['config'] = array('pagination');

At last I called the method to create links in my view template:

<?php echo $this->pagination->create_links(); ?>

This did not create any links. The configuration is being autoloaded correctly. I checked using...

<?php echo $this->config->item("num_links"); ?> <!-- this dislayed 9 -->

What am I missing here? Just for the record, putting the config inside the controller didn't work either.

Update #1- I have found out that the config settings are loading correctly but they are not reaching the library or something like that. Inside the pagination library - I did some hard coding to find out that per_page parameter was zero in there.

Update #2- I was mistaken when I said that putting the config inline wasn't working. It is working fine. The autoload isn't working.

Regards

+1  A: 

Your autoload line in your config file should be this

$autoload['libraries'] = array('pagination');

And you must have this line in you controller after your config array, before you use create_links() etc.

$this->pagination->initialize($config);
Nick Pyett
+1 though you neglected to mention that the OP doesn't need to auto load and manually load the pagination class
DRL
@Nick - `$autoload['libraries'] = array('pagination');` won't autoload the config file that I have created. I will autoload the library AFAIK.
ShiVik
A: 

Finally used this code to solve my problem...

$this->config->load("pagination");
$page_limit = $this->config->item("per_page");
$config['total_rows'] = $var; // Some variable count
$this->pagination->initialize($config);

This lets me define the config items in a file as well as initialize the items I want in controller like in my case, the total no. of rows - retrieved from database.

Regards

ShiVik