简体   繁体   中英

How to use pagination in codeigniter with segments?

I have one problem in Codeigniter pagination with segments. I need to pass segments with page number.

Example: http://www.mysite.com/app/controller/method/param1/param2/page_number

<?php

$this->load->library('pagination');
$config['base_url'] = 'http://localhost/welcome/par1/para2/';
$config['total_rows'] = 200;
$config['per_page'] = 20;

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

echo $this->pagination->create_links();

?>

Try using the URL helper function current_url() as your base url.

From the CI documentation ( http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html ):

current_url() - Returns the full URL (including segments) of the page being currently viewed.

So, in your situation, the controller would look like this:

$this->load->library('pagination');
$config['base_url'] = current_url();
$config['total_rows'] = 200;
$config['per_page'] = 20;

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

echo $this->pagination->create_links();

This method should allow you to have as many parameters as you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM