Welcome Guest, Not a member yet? Register   Sign In
Pagination links not updating correctly
#1

[eluser]Robert May[/eluser]
Simply put, as you change pages the numbers don't update, and the first page is always the one unclickable.
Now my code for this is a bit...odd and complex, so rather than try to explain what the hell I'm doing I was wondering if anyone could suggest possible causes or solutions that have worked for them before. I've tested without the complexity and it didn't work then either.

In case anyone actually wants to look through it, here's my function. A quick explanation is that I retrieve the pagination links separately using jQuery by passing the POST variable 'huh'='links', but after they've been properly rendered by the pagination library. It grabs the offset via either POST or the URL to allow debugging. And yes, the code is a bit of a mess - I have a deadline of Tuesday and it's a university project based more on functionality, so just ploughing through at the moment! :-)

Code:
function images($what){

        if($what == "list"){

            // load pagination class

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

            $this->load->helper('url');

            $config['base_url'] = '/index.php/admin/gallery/images/list';

            $config['per_page'] = 6;

            $config['full_tag_open'] = '<div id="pagination_links"><p>';

            $config['full_tag_close'] = '</p></div>';

            

            if($this->input->post('category')){

                $category = explode('_',$this->input->post('category'),2);

                $category = $category[1];

            }

            else {

                $category = 0;

            }

            

            $this->db->select('*')->from('gallery')->where('image_category', $category);

            $numRows = $this->db->get();

            $config['total_rows'] = $numRows->num_rows();

            

            if(!is_numeric($this->uri->segment(6))){

                $offset = $this->input->post('offset');

                if(!is_numeric($offset)){

                    $offset = explode("/", $offset);

                    $count = count($offset);

                    $count--;

                    $offset = $offset[$count];

                }

            }

            else {

                $offset = $this->uri->segment(6);

            }

            if($offset == NULL){

                $offset = 0;

            }

                

            $this->pagination->initialize($config);

            $images = $this->gallery_model->list_images($category,$config['per_page'],$offset);

            

            if($this->input->post('huh') == 'links'){

                // Create the links seperately for Ajax fun

                echo $this->pagination->create_links();

            }

            else {

                foreach($images as $image){

                    if($image['image_islive'] != 'TRUE'){

                        $islive = '<div class="gallery_admin_image_list_button_isnotlive ui-corner-tl" id="image_'.$image['image_id'].'_islive">Not Live</div>';

                    }

                    else {

                        $islive = '<div class="gallery_admin_image_list_button_islive ui-corner-tl" id="image_'.$image['image_id'].'_islive">Live</div>';

                    }

                    

                    echo '<div class="gallery_admin_upload_image_wrapper" id="'.$image['image_id'].'_'.$image['image_id'].'">

                            <div class="gallery_admin_upload_image_container" id="image_'.$image['image_id'].'">

                                    <ul class="gallery_admin_image_list" id="image_'.$image['image_id'].'_simple">

                                        <li class="gallery_admin_image_list_title">

                                            <div id="image_'.$image['image_id'].'_title" class="admin_input">'.$image['image_title'].'</div>

                                        </li>

                                        <li>

                                            <div><img src="/gallery/'.$image['image_file_squarethumb'].'"></div>

                                        </li>

                                        <li>

                                            <label for="image_'.$image['image_id'].'_islive">Select for multiple actions: &lt;input type="checkbox" id="image_'.$image['image_id'].'_multi" /&gt;&lt;/label>

                                        </li>

                                    </ul>

                                    <ul class="gallery_admin_image_list" id="image_'.$image['image_id'].'_detailed" style="display:none;">

                                        <li class="gallery_admin_image_list_title">

                                            <div id="image_'.$image['image_id'].'_title" class="admin_input">'.$image['image_title'].'</div>

                                        </li>

                                        <li>

                                            &lt;textarea id="image_'.$image['image_id'].'_comment"&gt;Comments/details&lt;/textarea&gt;

                                        </li>

                                    </ul>    

                                </div><div class="gallery_admin_image_list_button ui-corner-tr" id="'.$image['image_id'].'">Details</div>'.$islive.'</div>';

                }

            }

        }

    }
#2

[eluser]Robert May[/eluser]
Nevermind! I discovered that the pagination class only lets you pass the current page via the URL, so a quick bit of hacking was needed.

For anyone interested, if you want to pass the current page to the Pagination library by means other than the URL, comment out this section in Libraries/Pagination.php:

Code:
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
        {
            if ($CI->input->get($this->query_string_segment) != 0)
            {
                $this->cur_page = $CI->input->get($this->query_string_segment);
                
                // Prep the current page - no funny business!
                $this->cur_page = (int) $this->cur_page;
            }
        }
        else
        {
            if ($CI->uri->segment($this->uri_segment) != 0)
            {
                $this->cur_page = $CI->uri->segment($this->uri_segment);
                
                // Prep the current page - no funny business!
                $this->cur_page = (int) $this->cur_page;
            }
        }

And set it using $config['cur_page'] in your controller.

Just thought I'd post it here in case it ever comes in handy for someone else. Smile
#3

[eluser]TheFuzzy0ne[/eluser]
It's highly recommended that you don't hack any of the core files. You can simply extend them or override them. Copying the file to ./system/application/libraries and editing that file will cause CodeIgniter to use that file instead of the default core file.
#4

[eluser]Robert May[/eluser]
Ah ha, I may then do that instead. And with an if statement instead of commenting methinks :-)




Theme © iAndrew 2016 - Forum software by © MyBB