Welcome Guest, Not a member yet? Register   Sign In
Why am I getting these notices? I haven't before. Undefined offset / index for a custom calendar class.
#1

[eluser]Kinsbane[/eluser]
Hi folks,

Recently my work bought a new webserver with the latest LAMP setup. Our current server is PHP4, and this one is PHP 5.2.x. Not sure if this is related or not, but I was hoping I could get some troubleshooting assistance so my log files with CodeIgniter don't fill up with thousands of PHP Notice Errors.

So, here's the stuff that grabs the events for the current month:
Code:
//***** INSIDE Events controller
function calendar($month = '', $year = '')
    {
        //load the calendar library
        $this->load->library('DCCalendar');
        
        if(!$month) $month = date("n");
        if(!$year) $year = date("Y");
        $nextyear = $lastyear = $year;

        $nextmonth = $month + 1;
        if($nextmonth > 12) {
            $nextmonth -= 12;
            $nextyear ++;
        }
        $lastmonth = $month - 1;
        if($lastmonth <= 0) {
            $lastmonth += 12;
            $lastyear --;
        }
        $month_start = mktime(0,0,0,$month,1,$year,1);
        $month_end = mktime(0,0,0,$month+1,1,$year,1);
        $this->dccalendar->set_cal_url($this->config->item('base_url')."events/calendar/$lastmonth/$lastyear", $this->config->item('base_url')."calendar/$nextmonth/$nextyear");
                //get events for the month from the database
        $calevents = $this->DC->getEvents($month, $year);
        foreach($calevents->result_array() as $row)
        {
            
            if($row['event_date'] > $month_start and $row['event_date'] < $month_end) {
                //send the current event's data to the add_event function so the object can make a list of this month's events for sorting
                $this->dccalendar->add_event($row['event_title'], $row['event_date'], $row['event_length'], $this->config->item('base_url')."events/event/{$row['event_id']}", $row['event_status'], $row['event_id']);
            }
        }
        $data['page']['page_title'] = 'MRV Events Calendar &mdash; '.$month.'/'.$year;
        //the library returns an HTML string, which is displayed with the
                // display() function - we're just passing it the current month/year we're looking at
        $data['calbody'] = $this->dccalendar->display(mktime(0,0,0,$month,1,$year));
                //this displays a color key index to match events with their colors in the calendar view
        $data['calbody'] .= $this->dccalendar->display_colors();
        $this->load->view('general/start_page', $data);
        $this->load->view('general/menu_primary');
        $this->load->view('general/menu_secondary');
        $this->load->view('events/calendar_view', $data);
        $this->load->view('general/end_page');
    }

I have uploaded the CI Library I have here: http://www.kinsbane.net/temp/ci-class.dccalendar.txt

Was hoping someone could take a look and help me figure out why I'm getting a whole bunch of these Undefined offset errors. Here's a sample of the final array that the class works with. The $array[$date][$x][0] is the link to the event in the calendar, [1] is its current status, [2] is the name of the event, and [3] is the color assigned to the event in the calendar. Funnily enough, the undefined offset errors are because of the timestamps being used as indexes but I guess they get seen as offsets?
Code:
Array
(
    [1235894400] => Array
        (
            [0] => Array
                (
                    [0] => /events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )
        )
)
Array
(
    [1235894400] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )
        )
    [1235980800] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )

            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
    [1236067200] => Array
        (
            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
    [1236153600] => Array
        (
            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
)
Array
(
    [1235894400] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )
        )
    [1235980800] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )

            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
)

Here's a sample of what it looks like:
http://www.kinsbane.net/temp/calendar-sample.jpg


Messages In This Thread
Why am I getting these notices? I haven't before. Undefined offset / index for a custom calendar class. - by El Forum - 03-16-2009, 12:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB