Beginning Cakephp – Errata : Pg 106
The findByYear() function is messed up in the book. Thought I would post the correction to remind myself.
Correct!
function findByYear($year=null) {
$date = $year.'-01-01 00:00:00';
$end_date = $year.'-12-31 23:59:59';
return $this->find('all',
array(
'conditions' =>
array(
'DATE(Post.date) >' => $date,
'DATE(Post.date) <' => $end_date
)
)
);
}
Incorrect!
function findByYear($year=null) {
$date = $year.'-01-01 00:00:00';
$end_date = $year.'-12-31 23:59:59';
return $this->find('all',
array(
'conditions' =>
array(
'DATE(Post.date)' => '>'.$date,
'DATE(Post.date)' => '<'.$end_date
)
)
);
}
