1
votes

I'm working with a legacy CakePHP 1.1 application, and ideally need to modify some of the database queries. I'm much more used to working with 1.2 and 1.3 though, so I'm finding some of the "old style" code difficult to work with. The following query works in 1.1:

$events = $this->Event->findAll(array('Event.id'=>$event_ids));

I want to add another condition to that array, e.g., 'Event.start >' => [date]', but any attempt at all to do so seems to result in the query returning a null.

To add to my confusion, the Cake 1.1 Cookbook suggests that findAll works as follows:

  • findAll
  • string $conditions
  • array $fields
  • string $order
  • int $limit
  • int $page
  • int $recursive

If the $conditions parameter should be a string, then how come it often tends to come in the form of an array (not just in this application, I've seen it quite a lot elsewhere on the net)? What's the best route to getting the results I want from CakePHP 1.1? Short of upgrading the whole thing to a modern version of Cake?

1

1 Answers

2
votes

Looking at the CakePHP 1.1 API it suggests the first parameter, $conditions, takes a mixed value.

However, circa CakePHP 1.2 RC2, the comparison operator moved from the right to the left (or the from the value to the key) to save concatenation.

The following should hopefully work for you:

$events = $this->Event->findAll(array(
    'Event.id' => $event_ids,
    'Event.start' => '> ' . gmdate(DATE_ATOM),
));