leo, I hear what you're saying but I disagree in this case. The array-
based syntax for creating complex where conditions is the bomb! Sure,
the "LIKE" clause is a little unique, but once you learn it, it's no
big deal. I particularly like that you can avoid writing "IN" clauses
by doing this:
$array_of_user_ids = array(1,3,5,7,8,9,10);
$conditions = array('User.id' => $array_of_user_ids);
Of course if you prefer, Cake allows you to just write your conditions
as string fragments:
$conditions = 'User.id IN(1,3,5,7,8,9,10);
But if your list of Id's is already in an array, you have to do this:
$conditions = 'User.id IN(' . implode(',',$array_of_user_ids) . ')';
The fact that you can mix and match formats is awesome, too:
$conditions[] = array('User.id' => $array_of_user_ids);
$conditions[] = 'User.email LIKE [EMAIL PROTECTED]';
By default, the conditions will be "AND'ed" together. If you prefer to
be more explicit about that for readability, do it like this:
$conditions = array('AND'=>$conditions);
Or you could "OR" them together in the same fashion.
How can you complain about all this goodness?
On Jun 30, 4:36 am, leo <[EMAIL PROTECTED]> wrote:
> Seems to me that there are times when frameworks just make things more
> complicated and open to error. If a core developer can get it wrong,
> what chance do mere mortals stand? The whole array/SQL segment is not
> what I would describe as intuitive.
>
> On 29 Juny, 18:44, NOSLOW <[EMAIL PROTECTED]> wrote:
>
> > Just for the record (and to possibly save others from grief if they're
> > trying to do a LIKE in 1.2 RCx based on this example), it should be:
>
> > $conditions = array("or"=>(array(
> > 'edifici LIKE ?' => "%$searchText%",
> > 'adreca LIKE ?' => "%$searchText%"
> > )));
>
> > I'm sure Mariano just typed this off the cuff, as he's a core
> > developer and really knows his stuff ;)
>
> > The other way yields a SQL statement with single quotes around the
> > search term insided the percent signs (e.g. " LIKE %'my search
> > phrase'% "), which generates a SQL error.
>
> > BTW, checking the test cases in the core is very helpful in finding
> > examples to go by.
>
> > On Jun 16, 11:19 am, Mariano Iglesias <[EMAIL PROTECTED]>
> > wrote:
>
> > > Please read the release notes regardingLIKEand other SQL operators.
> > > That should be:
>
> > > $conditions= array("or"=>(array(
> > > 'edificiLIKE%?%' => $searchText,
> > > 'adrecaLIKE%?%' => $searchText
> > > )));
>
> > > On Mon, 2008-06-16 at 03:07 -0700, leo wrote:
> > > > Call me a misery, but I seem to be having more problems with RC1 than
> > > > I had with Beta.
>
> > > > The following works as expected in Beta but invariably returns an
> > > > empty set in RC1:
>
> > > > $conditions= array("or"=>(array('edifici' => 'LIKE%'.
> > > > $searchText.'%', 'adreca' => 'LIKE%'.$searchText.'%')));
> > > > $this->set('immobles', $this->paginate('Immoble',$conditions));
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---