Thursday, February 13, 2020

Be aware of Code Igniter 2 pagination configuration

While using Code Igniter pagination library, please pay attention on the configuration, especially for uri_segment, else it will take times to debug the weird pagination behavior.


    $this->load->library('pagination');

    $config = array(
        'base_url' => '/aaa/bbb/ccc/ddd/',
        'total_rows' => $count,
        'per_page' => 50,
        'uri_segment' => 5,
        'use_page_numbers' => TRUE,
        'num_links' => 5,
        'num_tag_open' => '
  • ', 'num_tag_close' => '
  • ', 'cur_page' => $page, ); $this->pagination->initialize($config);

    From the code above, if url is /aaa/bbb/ccc/ddd/{pagi here}, we should set the uri_segment to 5, if we set it to other number, the active page number will be set to a random number during we render our page, like it will be always stick to 1.

    No comments:

    Post a Comment

    Note: Only a member of this blog may post a comment.