[TYPO3-mvc] Most correct way to extract data from the DB for a simple categorized listing?

Henrik Møller Rasmussen info at hmrdesign.dk
Wed Apr 14 12:44:51 CEST 2010


On 13/04/10 18.31, Thomas "Thasmo" Deinhamer wrote:
> In your controller you can use a repository to find all desired
> products, you could use:
> $products = $myRepository->findByCategory($categoryObject);
>
> Then you can assign all products to the view:
> $this->view->assign('products', $products);
>
> In your template you can use the for viewhelper to display them:
>
> <f:for each="{products}" as="product">
> ...
> </f:for>
>
> If you want to display the categories and the products you need to
> assign the categories to the view and inside the for viewhelper you can
> use another for viewhelper to show the assigned products:
>
> <f:for each="{categories}" as="category">
>
> <h1>{category.title}</h1>
>
> <f:for each="{category.products}" as="product">
> {product.title}
> </f:for>
> </f:for>
>
> Good luck,
> Thomas
>
>
> Am 13.04.2010 08:14, schrieb Henrik Møller Rasmussen:
>> Hello,
>>
>> I'm playing around with extbase/fluid creating a small product catalog,
>> and I want to do a simple listing of the products based on category, and
>> sorted by date within each category.
>>
>> Products have a 1:n relationship to categories and a product has a date.
>>
>> The final list would be something like this:
>>
>> Category A:
>> - 13.04.10: Prod. A
>> - 11.04.10: Prod. B
>>
>> Category B:
>> - 12.04.10: Prod. C
>> - 01.04.10: Prod. D
>>
>> etc.
>>
>> In the old pre-extbase/fluid times, I would do a simple DB-call to fetch
>> all products sorted by "category,date DESC", and then loop through all
>> the products, and render the category each time the category changed.
>>
>> I have been thinking of how to do this in extbase, and couldn't figure
>> out a smart way. I played around with groupedFor, but I'm not quite sure
>> that is the way of doing it.
>>
>> So a little push in the right direction would be great! Thanks.
>>
>> Thanks for a very nice product and I'm already loving it for small
>> quick-and-dirty extensions like simple product listing etc.
>>
>> Best regards
>>
>> -Henrik

Hello Thomas,

Thanks for your reply.

How do you set the ordering of the products in the {category.products} 
list? Should you rewrite the getProducts() method on the category, to 
return a custom specified query?

Thanks

Henrik


More information about the TYPO3-project-typo3v4mvc mailing list