'CI multiple pagination in one view,
I try to use multiple pagination in codeigniter in the same view. My controler is:
public function gallery()
{
$config1 = array();
$config1["base_url"] = site_url("pages/gallery");
$config1["total_rows"] = $this->pagination_model->video_count();
$config1["per_page"] = 1;
$config1["uri_segment"] = 3;
$this->pagination->initialize($config1);
$page1 = ($this->uri->segment(3,0)) ? $this->uri->segment(3,0) : 0;
$data["videos"] = $this->pagination_model->fetch_video($config1["per_page"], $page);
$data["links1"] = $this->pagination->create_links();
$config2 = array();
$config2["base_url"] = site_url("pages/gallery").'/'.$this->uri->segment(3,0);
$config2["total_rows"] = $this->pagination_model->gallery_count();
$config2["per_page"] = 3;
$config2["uri_segment"] = 4;
$this->pagination->initialize($config2);
$page2 = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data["galleries"] = $this->pagination_model->fetch_gallery($config2["per_page"], $page2);
$data["links2"] = $this->pagination->create_links();
$this->template->gallery_view($data);
}
Pagination work ok on the first and second config, independence, but when i click page nr. 3 for ex. in pagination link1 on the pagination link2 go to nr. 3 (only page nr. content is OK), and on page 6 link1 but link 2 is incremented with +1.
Need to be on press click link1:
link1 ------------ link2
1 ---- curent_page_link2(default is link2 = '')
2 ---- curent_page_link2
3 ---- curent_page_link2
3 ---- curent_page_link2
But i have on press click link1:
link1 ---------- link2
1 ---- curent_page_link2(default is link2 = '')
2 ---- curent_page_link2(default is link2 = '')
3 ---- curent_page_link2 ( need to be (default is link2 = '') but i have activ link2 = '2' content from link2='')
4 ---- curent_page_link2
5 ---- curent_page_link2 ( need to be (default is link2 = '') but i have activ link2 = '3' content from link2='')
Sorry for my english.
Solution 1:[1]
I am not tested this. This may helps you. Use 'prefix' and 'suffix' for pagination in config1.
...
$config1 = array();
$config1["base_url"] = site_url("pages/gallery");
$config1["total_rows"] = $this->pagination_model->video_count();
$config1["per_page"] = 1;
$config1["uri_segment"] = 3;
////////////////////////////////////////////////////////
$config1['prefix'] = '';
$config1['suffix'] = '/'.$this->uri->segment(4,0);
////////////////////////////////////////////////////////
$this->pagination->initialize($config1);
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arjun Raj |
