acloudtree

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
			)
		)
	);
}

4 comments

  1. Drumjunky says:

    Thanks so much for posting this! I’ve been kicking myself for days trying to figure this out. I’m new to cake so I’m glad there are people out there looking out. I very much appreciate it.

  2. Klong says:

    “Thanks so much for posting this! I’ve been kicking myself for days trying to figure this out. I’m new to cake so I’m glad there are people out there looking out. I very much appreciate it.”

    Can’t say more…Thanks!

  3. ion says:

    Same Here !!!
    Thanks a lot … It’s just that the book is so good up to now and I have been wondering for the last 2 hours of what I am doing wrong. (actually I got to learn quite a few stuff from that process). Anyway, thanks to you and the Internet I’m back to track.

  4. Jared says:

    I’ve found quite a few erratas in the code examples so far, and I’m only half way through. Most I could repair but this one eluded me. Is there one central place on the web for all the corrections for this book?

Post a comment

Copyright © Jared Folkins
Programming, Computers, Writing, Economics, and Life

Powered by WordPress