[TYPO3-mvc] How and where should I sort my data?

Oliver Salzburg oliver.salzburg at googlemail.com
Tue Mar 20 16:51:39 CET 2012


On 2012-03-20 15:33, Oliver Salzburg wrote:
> I'm trying to get my feet wet with extbase/fluid development and am
> kind of confused about where to properly sort my collected data.
> 
> I only have 2 entities that are relevant: Item and Category.
> Every Item should only be in a single Category.
> 
> So far so good, everything is working pretty great. I get my list of
> Items in the frontend, but not sorted as I want them.
> So I added the following snippet to my ItemRepository:
> 
>   public function findThings() {
>     $query = $this->createQuery();
>     $query->setOrderings(
>       array(
>         "category" =>
> Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
>       )
>     );
> 
>     return $query->execute();
>   }
> 
> Great, now my Items are sorted the the ID of the Category.
> But what I *really* want is to sort them based on the *Name* of my
> Category.
> 
> I tried several approaches that seemed logical to me but either
> resulted in error messages or seemed to have no effect.
> 
> How is this generally solved?
> 
> Cheers
> Oliver

It seems like extbase is simply *too* convenient for me.
Changing my method to this, works great:
   public function findThings() {
     $query = $this->createQuery();
     $query->setOrderings(
       array(
         "category.name" =>
 Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
       )
     );

     return $query->execute();
   }

Actually one of the first things I tried, but I formatted "category"
incorrectly, causing an error and leading me on a wild goose chase.

Oliver


More information about the TYPO3-project-typo3v4mvc mailing list