[TYPO3-mvc] Dynamic queries in repository

Felix Oertel mehl at foertel.com
Thu Sep 9 11:25:16 CEST 2010


hi,

Am 09.09.10 11:07, schrieb Michael Ruhdorfer:
> so I can't do it the way I did - it has to be dynamically...
> has anyone an idea?

You can build up all the constraints dynamicly, put them into an array 
and then push it into the query later. Like:

if ($category) {
    $constraints[] = $query->in('category', (int)$category);
}

if ($country) {
    $constraints[] = $query->equals('country', $country);
}

At the end you build up the final query at just put the array in.

$query->matching($query->logicalAnd($constraints));

You can even put constrained constraints into the array ;) Like:

$contraints[] = $query->logicalOr($query->logicalAnd(x, y), 
$query->logicalOr(z, a));

Extbase will do all the hard work and merge everything into a big 
statement. ;-)

reagrds, foertel


More information about the TYPO3-project-typo3v4mvc mailing list