[TYPO3-mvc] repository chain multiple "likes"

Jochen Rau jochen.rau at typoplanet.de
Tue Dec 8 12:15:56 CET 2009


Hi Alex.

schrieb Alex Bailey:
> Hey,
>
> another little question from me :)
>
> At the moment im working on a search function to search for various
> fields in my database to do so I use the like function in the repository
>
> $query->matching($query->like($field, '%'.$this->search.'%'));
>
> This is working fine for me aslong as I use a single field to compare.
>
> Now I want to search multiple fields, so my idea was to chain the likes
> together in a foreach loop.
>
> foreach($this->searchFieldArray AS $field)
> $query->matching($query->like($field, '%'.$this->search.'%'));
>
> Now obvious this doesnt work since, it seems you cant just link them
> together like that.
>
> Does anybody have a clue what I can do in this situation to solve this?

$query->matching($query->logicalAnd($query->like(...), $query->like(...)));

That’s a bit weird for many fields but it should work.

OT ((Ahhrg, I want a domain specific language for that. PHP, please 
gimme a better syntax ;-) ))

Regards
Jochen

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list