[TYPO3-mvc] extbase SetOrderings doesn't work

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jan 24 16:21:22 CET 2011


Hey Johannes,

> I started to do my first experiences with extbase and fluid. But now, no
> book and no community is able to help me out of this problem.

maybe you've just been in the wrong community ;)

> My Controller and Repositories are working fine, but not the Orderings of
> the repository! It always orders by Uid descending!!
>
>
>
> BandRepository.php:
>
> public function listOfBandsInYearBy($year,$sortby,$sorttype){
>        $frage = $this->createQuery();
>        $frage ->  getQuerySettings()->setRespectEnableFields(TRUE);
>
>        if($sortby=='ORDER_ASCENDING'){
>                  $frage->matching($frage->equals('year',$year) );
>                  $frage->setOrderings(array($sorttype =>
> Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING) );
>                  return $frage->execute();
>        }
...
> }
>
>
> $sorttype can be 'name' (string) or 'dateadded' (int). (comes from Flexform)
>
> $sortby can be 'ORDER_ASCENDING' or 'ORDER_DESCENDING' (comes from Flexform)
>
> $year also comes from flexform
>
>
>
> I also tried to replace $sorttype by 'name' or 'dateadded'.
>
> I installed DevLog to see the SQL-Statement generated by extbase. It was
> totally correct! But the frontend shows always the wrong sorting!

How do you render the results in your templates and which extbase/fluid 
versions are you using?

Btw: You don't have to explicitly set "setRespectEnalbeFields" to TRUE - 
this is the default, and you have quite some redundancy in your 
repository function. Wouldn't it be wiser (and less error prone) to 
create only the orderings array depending on the if condition and write 
the rest of the query only once?

public function listOfBandxInYearBy($year, $orderBy, $orderDirection) {
	$query = $this->createQuery();
	$orderings = array(
		$orderBy => $orderDirection === 'ORDERNG_ASCENDING' ? 
Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING : 
Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
	);

	return $query->matching( $query->equals('year', intval($year))
		->setOrderings( $orderings )
		->execute();
}
-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list