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

Thomas Allmer at at delusionworld.com
Thu Oct 6 00:50:20 CEST 2011


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


-- 
+---------------------------------+-----------------------------------+
| Thomas Allmer                   |   http://www.delusionworld.com    |
| E-mail: at at delusionworld.com    |   phone: +43 699 16217064         |
+---------------------------------+-----------------------------------+


More information about the TYPO3-project-typo3v4mvc mailing list