问题
I have a simple model "item" with 3 properties: title, description, date
Now I want to have a list like this:
10.10.17:
title item 1
title item 5
12.10.17:
title item 8
and so on
According to groupedFor - grouping objects according to dates
I added a getter like
/**
* Get day month year of datetime
*
* @return int
*/
public function getDayMonthYearOfDatetime()
{
return (int)$this->datum->format('dmy');
}
My list view:
<f:groupedFor each="{items}" as="dayMonthYearOfDatetime" groupBy="dayMonthYearOfDatetime" groupKey="datum">
<tr>
<th>{datum}</th>
</tr>
<f:for each="{dayMonthYearOfDatetime}" as="calendar">
<tr>
<td>{item.title}</td>
</tr>
</f:for>
</f:groupedFor>
Now I get the following output:
101017 title item 1 title item 5
121017 title item 8
How to diplay the correct date "10.10.17" instead "101017"?
If I change my getter to:
return (int)$this->datum->format('d.m.y');
It doesn't work.
回答1:
return (int)$this->datum->format('d.m.y');
Remove the (int)
回答2:
You can't expect to have a grouping if you return int
from a date-string with dots.
Either you need to return string (but I don't know whether the function is allowed to return anything else than int) or you need to calculate your datestring from the calculated integer.
Try a viewhelper which does integer caclulations ( % 100, / 100 %100, /10000) or simple substrings (,0,2 ,2,2 ,4,2) to extract the values for day, month, year for a following concatenation.
回答3:
You can simply use the real date object of the first group-item.
So it would be
<f:format.date format="d.m.Y">{dayMonthYearOfDatetime.0.datum}</f:format>
来源:https://stackoverflow.com/questions/44753015/typo3-groupedfor-viewhelper-according-to-dates