[eluser]Unknown[/eluser]
Hi everyone.
I have a small problem in my crud.
Everything works perfectly, except for one small detail. I've choice to show 5 records per page.
Near to the name of the record in the list, i have the usual options such as update and delete.
When I delete the last record on the page, not showing previous page, but it remains on the same page giving message no records found, but showing pagination.
In practice, for example, i'm here:
Code:
http://www.mysite.com/webapps/categories/index/id_category/desc/10
deleting the last record of this page which is the third, not the url looks like this:
Code:
http://www.mysite.com/webapps/categories/index/id_category/desc/5
then going to page 2, but it remains as the first url shown above.
So I wrote in this way index method:
Code:
private $limit = 5;
public function index($order_column = '', $order_type = '', $offset = null)
{
if(empty($offset)) $offset = 0;
if(empty($order_column)) $order_column = 'id_category';
if(empty($order_type)) $order_type = 'desc';
$this->load->model('categories_model');
// This section of code improve the problem but not solve it
$last_item = $this->db->get('categories')->num_rows();
$how_many = $last_item - $offset;
if($how_many < 1 && $offset != 0)
{
$offset -= $this->limit;
}
// end
$data['records'] = $this->categories_model->retrieve_categories($this->limit, $order_column, $order_type, $offset);
$data['num_rec'] = $this->categories_model->record_count();
$config['base_url'] = '' . base_url() . 'categories/index/'.$order_column.'/'.$order_type.'/';
$config['total_rows'] = $data['num_rec'];
$config['per_page'] = $this->limit;
$config['uri_segment'] = 5;
$config['num_links'] = 2;
$config['full_tag_open'] = '<div id="pagination_middle">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['offset'] = $offset;
$data['order_column'] = $order_column;
$data['order_type'] = $order_type;
$this->load->view('template/header_view');
$this->load->view('template/menu_view');
$this->load->view('pages/categories_view', $data);
$this->load->view('template/footer_view');
$this->output->enable_profiler(TRUE);
}
Mostly it works, because you see the second page, and I no longer have the message of no records found, but the url is:
Code:
http://www.mysite.com/webapps/categories/index/id_category/desc/10
and the page number in the paging links, is not highlighted in strong.
I need something like set_segment, but I know that does not exist.
Does anyone have an idea?
Thanks