codeIgniter pagination- doesn't go to the next link of searched results codeIgniter pagination- doesn't go to the next link of searched results codeigniter codeigniter

codeIgniter pagination- doesn't go to the next link of searched results


Hey Hi please find the below controller code with pagination classes

/* start code of pagination */        $config                     = array();        $config["base_url"]         = base_url()."cms/manage_cms";        if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");        if (count($_GET) > 0) $config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;        //$page = 0;        $config["total_rows"]       = count($this->mdl_cms->getAllCmsByCondition($searchindex,$orderField,$orderby,$rowsPerPage,$page,false));        if($config["total_rows"] < $rowsPerPage){            $page = 0;        }        $config["per_page"]         = $rowsPerPage;        //$config["uri_segment"]      = 3;        $config['full_tag_open']    = '<div class="pagination"><ul>';        $config['full_tag_close']   = '</ul></div><!--pagination-->';        $config['first_link'] = '« First';        $config['first_tag_open'] = '<li class="prev page">';        $config['first_tag_close'] = '</li>';        $config['last_link'] = 'Last »';        $config['last_tag_open'] = '<li class="next page">';        $config['last_tag_close'] = '</li>';        $config['next_link'] = 'Next →';        $config['next_tag_open'] = '<li class="next page">';        $config['next_tag_close'] = '</li>';        $config['prev_link'] = '← Previous';        $config['prev_tag_open'] = '<li class="prev page">';        $config['prev_tag_close'] = '</li>';        $config['cur_tag_open']     = '<li class="active"><a href="">';        $config['cur_tag_close']    = '</a></li>';        $config['num_tag_open']     = '<li class="page">';        $config['num_tag_close']    = '</li>';        $this->pagination->initialize($config);  // Load pagination class         $usersArr = $this->mdl_cms->getAllCmsByCondition($searchindex,$orderField,$orderby,$rowsPerPage,$page,true);         //echo $this->db->last_query(); //die;        $data["links"] = $this->pagination->create_links(); // Create pagination links

Hope it will work for you


Try adding

$config['use_page_numbers'] = TRUE;

And Make

$config['uri_segment'] = 4;

To

$config['uri_segment'] = 3;

Might need to set up your routes.php

$routes['dashboard/manage_bookings/(:any)'] = "dashboard/manage_bookings/$1"

CI2 http://www.codeigniter.com/userguide2/general/routing.html

CI3 http://www.codeigniter.com/user_guide/general/routing.html


You are taking the $time, $title, $payment, $date_from, $date_to variables from POST.

The paginiation links are like - home/search_reservations/2

once user clicks on those links the search data from post is lost. you need to keep your search parameters on the record if you want them to affect all the pages.

2 ways to do that-

1) use GET instead of POST. keep your search parameters in the query string of your generated pagination links. This way all the pages will have the search parameters. Also useful if you want to share/bookmark a specific page of the search result. E.g your pages will be linked like -

www.yoursite.com/home/search_reservations/2?time=123&title=123&payment=123&date_from=123&date_to=123 

2) keep the search parameter in session. A lot messier in the code but prettier in the URL.