Reputation: 199
I have issue with uri_string()
and pagination with codeigniter
My Code is:
<?php echo anchor(site_url(uri_string().'/'.$item->url_product),$item->name_product);?>
My current url (page 2, $config['per_page'] = 3
):
http://localhost:8080/ci/index.php/product/phone/page/3/
Run the code and get result (since I used pagination) for product URL:
http://localhost:8080/ci/index.php/product/phone/page/3/lumia_950_xl
But, I want corecting that URL like this:
http://localhost:8080/ci/index.php/product/phone/lumia_950_xl
I want eliminating page/3/
in the output. How can I solve it?
In my head now
(if any 'page/3/' string at site_url())
{
delete 'page/3/';
}
But I think there is another more easy way rather than using if statement like that, somebody? Thanks
OK finally I using replace statement, since no anybody give point here
$url_produk = uri_string();
$patern_url[0] = '(\/page\/\d)';
$patern_url[1] = '(\/page)';
$url_produk = preg_replace($patern_url, '', $url_produk);
Upvotes: 1
Views: 757
Reputation: 612
You can refer this code. This is the i have done pagination in Codeigniter.
public function managecategory() {
$this->load->helper(array('form', 'url'));
$this->load->view('moderator/templates/header');
$this->load->view('moderator/templates/sidebar');
$parent = '0';
$data['catdata'] = $this->b2bcategory_model->form_select($parent);
$this->load->library('pagination');
// bootstrap style for maintaining pagination
$config = array();
$config["base_url"] = base_url() . "moderator/B2BCategory/managecategory";
$config["total_rows"] = $this->b2bcategory_model->record_count();
$config["per_page"] = 20;
$config["uri_segment"] = 4;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = 'first';
$config['last_link'] = 'last';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data["results"] = $this->b2bcategory_model->fetch_data($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('moderator/managecategory', $data);
$this->load->view('moderator/templates/footer');
}
Upvotes: 1