[TYPO3-mvc] Using repository inside an entity
Jochen Rau
jochen.rau at typoplanet.de
Mon Apr 26 09:17:46 CEST 2010
Hi Henrik.
On 25.04.10 21:48, Henrik Møller Rasmussen wrote:
> 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.
Maybe the Tx_Fluid_ViewHelpers_GroupedForViewHelper is your friend here.
Just fetch all your items and group them in the template. Here is the
php comment:
/**
* Grouped loop view helper.
* Loops through the specified values
*
* = Examples =
*
* <code title="Simple">
* <f:groupedFor each="{0: {name: 'apple', color: 'green'}, 1: {name:
'cherry', color: 'red'}, 2: {name: 'banana', color: 'yellow'}, 3: {name:
'strawberry', color: 'red'}}" as="fruitsOfThisColor" groupBy="color">
* <f:for each="{fruitsOfThisColor}" as="fruit">
* {fruit.name}
* </f:for>
* </f:groupedFor>
* </code>
*
* Output:
* apple cherry strawberry banana
*
* <code title="Two dimensional list">
* <ul>
* <f:groupedFor each="{0: {name: 'apple', color: 'green'}, 1: {name:
'cherry', color: 'red'}, 2: {name: 'banana', color: 'yellow'}, 3: {name:
'strawberry', color: 'red'}}" as="fruitsOfThisColor" groupBy="color"
groupKey="color">
* <li>
* {color} fruits:
* <ul>
* <f:for each="{fruitsOfThisColor}" as="fruit" key="label">
* <li>{label}: {fruit.name}</li>
* </f:for>
* </ul>
* </li>
* </f:groupedFor>
* </ul>
* </code>
*
* Output:
* <ul>
* <li>green fruits
* <ul>
* <li>0: apple</li>
* </ul>
* </li>
* <li>red fruits
* <ul>
* <li>1: cherry</li>
* </ul>
* <ul>
* <li>3: strawberry</li>
* </ul>
* </li>
* <li>yellow fruits
* <ul>
* <li>2: banana</li>
* </ul>
* </li>
* </ul>
*
* @version $Id$
* @package Fluid
* @subpackage ViewHelpers
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General
Public License, version 3 or later
* @api
* @scope prototype
*/
class Tx_Fluid_ViewHelpers_GroupedForViewHelper extends
Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
Regards
Jochen
More information about the TYPO3-project-typo3v4mvc
mailing list