Reputation: 9585
I just implemented pagination in my website www.reviewongadgets.com
When I click the home page it's divided into two pages which is correct but when I click on next link it shows the URL as
http://www.reviewongadgets.com/home/10
which is also correct but when I come back to previous page number it displays URL as
http://www.reviewongadgets.com/home/home/
So can you please help resolve this problem? Below is the controller snippet where $url
is http://www.reviewongadgets.com/home
$config['base_url'] = $url;
$config['total_rows'] = $this->MiscellaneousModel->countEntries();
$config['per_page'] = 10;
$base_url = site_url('/');
$config['uri_segment'] = '2';
//$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
Upvotes: 0
Views: 704
Reputation: 4592
This should work for you(famous last words)
//Add this to your routes
$route['home/(:num)'] = 'home/index/$1';
public function index($offset=0){
$limit = $this->config->item('pagination_per_page'); // default 10
//find data based on limits and offset
$query = //you query LIMIT = $limit OFFSET = $offset
$count = //count the number of rows returned by $query
//init pagination attributes
$config = array(
'base_url' => site_url('home'),
'total_rows' => $count,
'per_page' => $limit,
'uri_segment' => 2
);
$this->pagination->initialize($config);
//load the view and pagination data
$this->load->view('some_view', array(
'pagination' => $this->pagination->create_links(),
'data' => //data return from $query as object or array
));
}
Upvotes: 1
Reputation: 25435
The problem might be on how you define the base_url, since you give it a variable but you didn't tell where and how you assign a value to it. Try with:
$config['base_url'] = site_url('home');
$config['total_rows'] = $this->MiscellaneousModel->countEntries();
$config['per_page'] = 10;
$config['uri_segment'] = '2';
Since you're using the index method, maybe specifying it can solve the issue (I had once a similar problem and that did work)
$config['base_url'] = site_url('home/index');
Upvotes: 0