I believe quite recently the syntax was changed and comparison
operators etc should now be placed in the left-hand side of the
array.  I think this was done for security to reduce chances of  SQL
injection.  In that respect,  I think you may have found a place where
the book may be a little out of date.  I think therefore the code
would be something like this.

find('all',array('conditions'=>array('DATE(Post.date) >' =>
$date,'DATE(Post.date) <' => $end_date)));

See http://book.cakephp.org/view/74/Complex-Find-Conditions


On Sep 19, 1:36 am, jabocs <[EMAIL PROTECTED]> wrote:
> I am going through the Apress book, and I ran across an issue that I
> had to use the Cake API to resolve.  (For Reference in book.. this is
> on page 106)
>
> The function it gave me to put into the Post model for the blog
> application is as follows:
>
> 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)));
>
> }
>
> Basically I was getting nothing returned... So I turned to the API and
> found the findAll and find model functions and I changed my code for
> the return to:
>
> return $this->findAll("Post.date > '".$date."' AND Post.date < '".
> $end_date."'");
>
> Now it works... Did I just stumble on some bad code in the book?  Or
> should the syntax given in the book supposed to have worked?
>
> Thanks,
> Jason Hardywww.loudcreative.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to