Created
February 11, 2016 11:48
-
-
Save rcerrejon/923435854a0f23db1d6a to your computer and use it in GitHub Desktop.
Extbase FindBy m:m relation (Categories)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//in Repository | |
/** | |
* Findby Categories | |
* | |
* @param type $categories | |
* @return type | |
*/ | |
public function findByCategories($categories) { | |
$query = $this->createQuery(); | |
foreach ($categories as $category) { | |
$constraint[] = $query->contains('category', $category); | |
} | |
$result = $query->matching($query->logicalAnd($query->logicalAnd($constraint)))->execute(); | |
if (count($result) > 0) { | |
return $result; | |
} | |
} | |
//in Controller | |
//Find items by Categories | |
$itemByCat = $this->yourRepository->findByCategories($item->getCategory()); | |
$this->view->assign('itemsbycategories', $itemByCat); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment