• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination and Calendar together?

#1
[eluser]Matrices[/eluser]
Hello fellow CIs,

I'm creating an events page for a client of mine and I was stoked to see that CI has a built in Calendar creator! So I got that to work perfectly fine with all my events. However, I realize that there will be lots of events each day for this particular page, and I went about initializing the Pagination for it. But it's quite broken. I'm pretty sure it's got something to do with the fact that both the Calendar and the Pagination mods are using the uri segments (which fluctuate between using 0-3 segments with the calendar).

The Pagination links are created, but ALL the events are showing (the query results aren't being truncated like they should). And when you click on any pagination link, the query results go blank.

The Calendar works fine, except after you click on a Pagination link.

Code:
function calendar()
    {
        // Build the calendar
        $prefs = array (
            'show_next_prev' => TRUE,
            'next_prev_url' => base_url().'index.php/events/calendar'
        );
        
        
        // Get the calendar set day and year; else get today's day and year
        if (!$this->uri->segment(5)) $day = date("d");
        else $day = $this->uri->segment(5);
        
        if (!$this->uri->segment(4)) $month = date("m");
        else $month = $this->uri->segment(4);
        
        if (!$this->uri->segment(3)) $year = date("Y");
        else $year = $this->uri->segment(3);
        
        $caldata = array();
        for ( $i = 1; $i < 32; $i = $i + 1) {
          
          if ($i < 10) $seg = '0'.$i;
          else $seg = $i;
          
          $caldata[$i] = base_url().'index.php/events/calendar/'.$year.'/'.$month.'/'.$seg;

        }
        
        $this->calendar->initialize($prefs);
        $data['my_calendar'] = $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4), $caldata);
        $data['highlighted_controller'] = highlight_file("events.php", TRUE);

        // Get Events
        if ($this->uri->segment(5)) {
          $date = $year.'-'.$month.'-'.$day;
          $this->db->where('event_date', $date);
        }
        else {
          $date = $year.'-'.$month;
          $this->db->like('event_date', $date);
        }
        $this->db->order_by('event_date');
        $data['query'] = $this->db->get('events');
        $item_count = count($data['query']->result());
        
        // Initialize Pagination
        $config['base_url'] = $this->base_uri;
        $config['total_rows'] = $item_count;
        $config['per_page'] = '3';
        $this->pagination->initialize($config);
        
        $data['cat'] = $this->cat;
        $this->load->view('event_list', $data);

    }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.