[TYPO3-mvc] Best practice: where to prepare a model property and how to iterate

Jochen Rau jochen.rau at typoplanet.de
Mon Jul 19 18:01:52 CEST 2010


Hi Gerhard.

On 2010-07-19, Gerhard Mehsel <sparking at gmx.net> wrote:
> I'm just coding my first extbase/fluid extension and have a question how 
> to achieve the following at a good/extbase way.

Welcome on the list!

> A user creates a database record in BE where he has to select a date. 
> Afterwards in FE this date is used to categorize the database records.
>
> An example:
> The user creates three database records with the three dates: 
> 2010-07-12, 2010-06-11 and 2011-01-12.
>
> Now in FE view I want to render two main tabs named "2010" and "2011", 
> first with two subtabs named "07" and "06" and the second with one 
> subtab named "01".
>
> In my fluid template I iterate over the DB record objects. And these 
> objects have one property "date" but I need to split that dates into 
> year and month to get the information for tabs and subtabs.
>
> _Where_ to put that date-split stuff? I think I have to code some 
> getYear(), getMonth() methods in my model. Is that the correct position? 

That might suit.

> Or do I do that in controller or in fluid template?

The controller is not in charge of to manipulating domain related data. You can also put the functionality into a ViewHelper, esp. if it is only related to the output.

> Another question: I fetch the above list of DB records within the 
> list-controller and a repository method findAll(). Now I have a flat 
> list of objects. How and where should I prepare the object list so that 
> I can render my tabs and subtabs, because they have to be nested 
> correctly. Pseudo code to clarify what I mean:
><div class="tab_uid1"><h1>2010</h1>
>    <div class="subtab_uid1">07</div>
>    <div class="subtab_uid2">06</div>
></div>
><!-- now I have to repeat the stuff to get next tab -->
><div class="tab_uid2"><h1>2011</h1>
>    <div class="subtab_uid1">01</div>
></div>

The GroupedForViewHelper might be the right choice in combination with the getYear() method in your domain object.

Regards
Jochen


More information about the TYPO3-project-typo3v4mvc mailing list