[Flow] Simple Search

Sascha Reule mail at sascha-reule.de
Wed Jun 17 08:45:56 CEST 2015


Hello Patric,

when you’re using the „equals“ operation, the searchstring must exactly match the property!

If you want a SQL LIKE search operation you have to use the  $query2->like() method. But don’t forget to wrap your searchstring with the % character!

$constraintArr[] = $query2->like($property, "%" . $filter . "%");

And of course, you can skip the iteration of the queryResult and assign it directly to Fluid.

// You don't need this!
// while($result2 = $results2->current()){
//     $results2->next();
// }


Sascha Reule
Sent with Airmail





Am 15. Juni 2015 bei 18:05:08, Patric Eckhart (mail at patriceckhart.com<mailto:mail at patriceckhart.com>) schrieb:

Hey guys,

I would create a simple search action in my controller.

With this code I have tried to search my database, but I get 0 results.

I want to check if $searchstring occurs in one of the fields

$filterArr = array('title' => $searchstring, 'description' => $searchstring, 'fullname' => $searchstring, 'thingcode' => $searchstring);

$classname2 = '\My\Projekt\Domain\Model\Thing';
$query2 = $this->persistenceManager->createQueryForType($classname2);

foreach($filterArr as $property => $filter) {
if(isset($filter)) {
$constraintArr[] = $query2->equals($property, $filter);
}
}

$results2 = $query2->matching($query2->logicalOr($constraintArr))->execute();
while($result2 = $results2->current()){
$results2->next();
}

$this->view->assign('searchresults', $results2);
_______________________________________________
Flow mailing list
Flow at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/flow


More information about the Flow mailing list