CodeIgniter Forums
How to set Pagination in order to redirect the page to the same url ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How to set Pagination in order to redirect the page to the same url ? (/showthread.php?tid=22351)



How to set Pagination in order to redirect the page to the same url ? - El Forum - 09-06-2009

[eluser]Unknown[/eluser]
Hi !

I'm newbie in the Frameworks world. I've looked through lot others as well but the performance of CI was the best. I've started to learn it through the tutorials, but I would like to develop it to get more know-how in CI.
So under this message I attached the code that response the first page and it's entries with the pagination script. But it isn't work well because there is some problem with the url and I don't know how i should modify to work properly ! So ... How should I modify the script to this action handle the
http://localhost/blog/ and the http://localhost/blog/index.php?test=test&page=2 url query as well.

Can someone help me ?

THX ! :-)

function index(){
$data['title']="CodeIgniter blog";
$data['heading']="My blog heading";
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/blog/index.php?test=1';
$config['page_query_string']=true;
$config['total_rows'] = $this->db->count_all('entries');
$config['per_page'] = '2';
$this->pagination->initialize($config);
if($this->uri->segment(2) == false ){
$start=0;
}else if($this->uri->segment(2) == true){
$start=$this->uri->segment(2);
}
$limit=2+$start;
$data['query']=$this->db->get('entries',$limit,2);
$data['pager'] = $this->pagination->create_links();
$this->load->view('blog_view',$data);

}


How to set Pagination in order to redirect the page to the same url ? - El Forum - 09-07-2009

[eluser]n0xie[/eluser]
Why do you use Query String in your URL? It's much easier to do this:

Code:
function index()
{
    $this->page();
}

function page($offset = 0)
{
        $limit = 2;
        // this should really be a model where you can give the offset and the limit
        $totalrows = $this->db->count_all(‘entries’);

        $config['base_url'] = site_url('nameofyourcontroller/page');
        $config['total_rows'] = $totalrows;
        $config['per_page'] = $limit;
        $this->pagination->initialize($config);

}



How to set Pagination in order to redirect the page to the same url ? - El Forum - 09-07-2009

[eluser]Unknown[/eluser]
Thanks your code was really helpful! Smile