I am relatively new to Cake PHP framework and was trying few things in it. I have made a blog databse. I was trying to view an array of number of posts made in a particular year using the debug() function. I wrote the following function in the post model.
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)));
}
Then I included a read function in the posts_controller.
function read($year=null) {
if (!$year) {
$this->Session->setFlash('Please supply a year');
$this->redirect(array('action'=>'index'));
}
$this->set('posts',$this->Post->findByYear($year));
}
Finally, a created a read view file(read.ctp) and included the debug function in that
<?php debug($posts) ?>
Now, the problem is that I am getting an empty array when I launch the action in the URL: http://localhost/posts/read/2009 I already have 3 posts but I am not getting any of them in the array. What am I missing?