[TYPO3-mvc] Using repository inside an entity

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Sun Apr 25 23:11:56 CEST 2010


You could also do it with the template only:

<f:for each="{categories}" as="category">
	<if condition="{f:count(subject: 'category.products')} > 0">
		{category.title}
	</f:if>
</f:for>

Thomas

Am 25.04.2010 21:48, schrieb Henrik Møller Rasmussen:
> Hello Franz,
>
> Thanks for your reply.
>
> My first thought was to create this method in the ItemRepository.. But
> the situation is, that I want to loop through all categories, rendering
> items inside each category. But each category should only be rendered if
> it contains items for sale.
>
> The way I solved it was by creating this getItemsForSale method on the
> categories. Now I could condition on category.itemsForSale, and loop
> through them easily afterward. I couldn't figure out a solution that did
> this using the repository.
>
> Does it make sense what I just described?
>
> - Henrik
>
> On 25/04/10 15.31, Franz Koch wrote:
>> Hey,
>>
>>> /**
>>> * Returns all items for sale in this category
>>> *
>>> * @return
>>> Tx_Extbase_Persistence_ObjectStorage<Tx_Dabmarket_Domain_Model_Item>
>>> */
>>> public function getItemsForSale() {
>>> $this->itemRepository =
>>> t3lib_div::makeInstance('Tx_Dabmarket_Domain_Repository_ItemRepository');
>>>
>>> return $this->itemRepository->findForSaleByCategory($this);
>>> }
>>
>> I see one big problem with this: repeated calls. Assume a FLUID template
>> like this:
>>
>> <f:if condition="{f:count(subject: myObject.itemsForSale)}">
>> <f:for each="{myObject.itemsForSale}" as="item">do something</f:for>
>> </f:if>
>>
>>
>> In such a situation every use of the property "itemsForSale" will
>> trigger your method and thus fetch the items over and over again from
>> the repository, so you should consider making use of some internal
>> "cache".
>> A better approach might be to move all the logic with the cache etc to a
>> dedicated service and only call this service from inside your model.
>>
>> $this->myService->getItemsForSaleByProduct($this);
>>
>


More information about the TYPO3-project-typo3v4mvc mailing list