[TYPO3-mvc] sorting the values of a for-loop

Christian Kartnig office at hahnepeter.de
Thu Oct 6 09:40:47 CEST 2011


Hi!

Another possibility is to set the sorting via TCA. But you are 
restricted to one column and 'ASC' is hardcoded for the sorting.
(Tim Schoch posted a hack to overcome this in this list, see: "Sorting 
of StorageObject's with extended foreign_sortby field")

I also used custom repository methods, but it's not satisfying either, 
because if I have to write a custom method everytime I need sorting, all 
the getters don't quite make sense anymore...

It would be so nice if Extbase respected the defaultOrderings also in 
getters...

Best regards,
Christian


Am 06.10.2011 00:50, schrieb Thomas Allmer:
> hey Christian,
>
> I now use in most my repositories something like this
> /**
> * Finds all items of the repository ordered by the $orderings.
> *
> * @param array $orderings
> * @return array Matched labors
> */
> public function findAllOrdered($orderings = array()) {
> $result = $this->createQuery()->setOrderings($orderings)->execute();
> return $result;
> }
>
> and you can use it like this...
>
> $this->myRepository->findAllOrdered(array('start' =>
> Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING);
>
> cheers
>
> On 05.10.2011 10:37, Christian Essl wrote:
>> Hi,
>>
>> I have a "kurstermin"-Model, which contains a start-date and an
>> end-date, and the category it belongs to. Now I first sort the
>> kurstermine by their category and then print out the dates with a
>> for-loop:
>>
>> <f:groupedFor each="{kurs.kursTermin}" as="kurstermineByCategory"
>> groupBy=" category " groupKey=" category">
>> <td>
>> <f:for each="{kurstermineByCategory}" as="kurstermin" key="von">
>> <f:format.date format="d.m.y">{kurstermin.start}</f:format.date>
>> -<f:format.date format="d.m.y">{kurstermin.end}</f:format.date><br />
>> </f:for>
>> </td>
>> </f:groupedFor>
>>
>> But by default the values are sorted by the uid. To sort the values by
>> the start-date, I inserted the following inside my Repository:
>>
>> class Tx_Extensionname_Domain_Repository_KursterminRepository extends
>> Tx_Extbase_Persistence_Repository {
>>
>> protected $defaultOrderings = array('start' =>
>> Tx_Extbase_Persistence_Query::ORDER_ASCENDING);
>> }
>>
>> ...but it doesn't seem to change anything. There are not custom
>> methods in the Repository which could override the settings. So what
>> is the best way to sort the output of a for-loop?
>>
>> Regards,
>> Christian
>
>



More information about the TYPO3-project-typo3v4mvc mailing list