Welcome Guest, Not a member yet? Register   Sign In
Using 'cur_page' in Pagination class
#1

Hello,

I was wandering, if this usage scenario of Pagination class is correct:

PHP Code:
public function display_users()
{
    $all_users_count $this->User_model->all_users_count();

    $config = array();
    $config['page_query_string'] = TRUE;
    $config['query_string_segment'] = "page";
    $config['use_page_numbers'] = TRUE;
    $config['per_page'] = 8;

    $config['base_url'] = site_url('Main/display_users');
    $config['total_rows'] = $all_users_count;
    $this->pagination->initialize($config);

    $data['pagination_links'] = $this->pagination->create_links();

    // Here, create_links() has set the pagination->cur_page to the value from url,
    // so 'cur_page' can theoretically be used now

    $page_start_i $config['per_page'] * ($this->pagination->cur_page 1);

    // SELECT * FROM 'users' LIMIT $page_start_i, $config['per_page'];
    $data['display_users'] = $this->User_model->get_users_limit($page_start_i$config['per_page']); 

    $this->load->view('all_users'$data);


I need to know current page number to calculate offset for SELECT query.
I can take the page number from url, but then i have to check if  it's integer and within range of existing pages.
Instead, I use pagination->cur_page (after calling create_links() ), because  all of that validation and cheking
is done in  create_links().


So, my question is, can I use pagination->cur_page in this way?

Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB