[TYPO3-english] Extbase: Get selected childs from relation

Mikel lists at con-version.com
Fri Sep 13 18:11:09 CEST 2013


I gave it another try and solved it that way --> instead of the 
categories I created a query to get the latest documents for each 
category and assign that array to the view.
Within the view the GroupedFor ViewHelper helped me out.

Maybe my code helps also someone else in the future:

The query:

public function findRecentByCategory($category) {
         $query = $this->createQuery();
         $query->setOrderings(array('crdate' => 
\TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
         $query->matching($query->equals('categories', $category));
         $query->setLimit((integer)1);
         return $query->execute()->getFirst();
}

The rendering within the view:

<f:groupedFor each="{documents}" as="myDoc" groupBy="categories" 
groupKey="categories">

         <h2>{categories.title}</h2>

         <f:for each="{myDoc}" as="doc">
             <h3>{doc.title}</h3>
         </f:for>

     </f:groupedFor>

> Hmm if I understand correctly you want to do something like that:
> $DocumentRepository->findBy[SomeProperty](PropertyValue);
>
> If you need to apply the filtering only to some documents within a 
> category then get the category first, then you can either loop through 
> the category or you maybe could write a custom query .
>
> (if you dont already have it, maybe this could help: 
> http://www.typovision.de/fileadmin/slides/ExtbaseFluidCheatSheetTypovision.pdf)
> _______________________________________________
> TYPO3-english mailing list
> TYPO3-english at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english



More information about the TYPO3-english mailing list