[TYPO3-mvc] Displaying a model property of type 'select' as form field using Extbase and Fluid
Nathan Lenz
typo3 at k9tfk.com
Wed Jan 20 16:35:14 CET 2010
Thomas,
Currently the Units in my example aren't stored in a table or
repository. It's just fixed list much like how your 'items' list is
hard coded in the TCA definition. So unfortunately, its duplicated.
The idea of the service was just to encapsulate the hard coding and let
me worry about were the data comes from later and also to group together
unit related functions.
Also, I used a service because you can't use a repository to fetch value
objects (which I consider units to be). Since value objects don't have
an aggregate root.
The service contains the following methods so far:
Domain_Model_Unit
id - integer constant (not best practice) 1 always means ounces.
name - ounce
pluralName - ounces
symbol - oz
description (optional, for non-standard units)
I don't assign the Domain_Model_Unit object as a property to any other
Models because the mapping a value object from a select form element
wasn't working for me. Later I'll try to figure that out. For now, I
just assign the "id" constant as an integer property to other Models
that need a unit. I'd like to refactor this in the future. For now, I
need it to just work.
UnitService
getDefinedUnit($unit)
Given an integer constant, it returns a "Unit" value object.
getStandardUnits()
Get an array containing all the standard "Unit" objects. This
is what I use for <f:form.select>'s option parameter.
The final thing I created to help me with this is a viewHelper:
<myext:measure number="{someobj.amount}" unit="{someobj.unit}" />
This will output <span class="num">1 1/2</span> <span
class="unit">ounces</span>
--Nathan
Thomas "Thasmo" Deinhamer wrote:
> Thanks for sharing your idea,
> how do you define of which table/field
> you want to get the units?
>
> Do you mind also sharing some more
> bits of your service class?
>
> Would be really great and helpful!
>
> Thanks a lot,
> Thomas
>
More information about the TYPO3-project-typo3v4mvc
mailing list