Calendar plugin error

3 messages Options
Embed this post
Permalink
michaelGregoire

Calendar plugin error

Reply Threaded More More options
Print post
Permalink
I noticed an error in the Calendar helper's render method.

The sixth week doesn't render with the code that's in the book:

if($day < strftime("%d",$lastdate)) { // check if there is a sixth week
      $out .= '<tr>';
      for($i=22; $i<=28; $i++) {
        if(strftime("%d", $lastdate) < $day) {
          $out .= '<td> </td>';
        } else {
          $out .= '<td>'.$day.'<br />';
          $out .= $this->events($month, $day, $year, $events);
          $out .= '</td>';
          $day++;
        }
      }
      $out .= '</tr>';
}

As far as I can tell it needs to be changed to the following to work:

if($day <= strftime("%d",$lastdate)) { // check if there is a sixth week
      $out .= '<tr>';
      for($i=36; $i<=42; $i++) {
        if(strftime("%d", $lastdate) < $day) {
          $out .= '<td> </td>';
        } else {
          $out .= '<td>'.$day.'<br />';
          $out .= $this->events($month, $day, $year, $events);
          $out .= '</td>';
          $day++;
        }
      }
      $out .= '</tr>';
}


davidgolding

Re: Calendar plugin error

Reply Threaded More More options
Print post
Permalink
Ah, just missed the numbers there. Thanks for the tip. I'll submit this to the errata.
--Dave

Author, "Beginning CakePHP: From Novice to Professional"

[ get your copy at: http://www.amazon.com/Beginning-CakePHP-Novice-Professional/dp/1430209771/ ]
michaelGregoire

Re: Calendar plugin error

Reply Threaded More More options
Print post
Permalink
Actually, also notice the first test '<=' instead of the book's '<'. Otherwise, if the first day of the week is the last day of the month, you won't get your week at all.