[TYPO3-mvc] How to load a list of value objects?
Henjo Hoeksma
me at henjohoeksma.nl
Wed Apr 13 11:32:39 CEST 2011
On 2011-04-11 17:20:13 +0200, François Suter said:
> Hi,
>
>> I have an entity which is related to one or more items that are value
>> objects. In the (Fluid) input form I would like to display the selection
>> of those items as a select field with multiple choices. How do I load
>> the list of available value objects into my select field? Since the
>> value objects have no dedicated repository class, how do I access them?
>
> I've managed to solve this issue, but I've no idea whether this was the
> right way to do it, so I would appreciate if someone could comment on
> that:
>
> // Get the list of sleeping drugs from the storage
> /** @var $queryFactory Tx_Extbase_Persistence_QueryFactory */
> $queryFactory =
> $this->objectManager->get('Tx_Extbase_Persistence_QueryFactory');
> /** @var $query Tx_Extbase_Persistence_QueryInterface */
> $query = $queryFactory->create('Tx_Latourrisk_Domain_Model_SleepingDrug');
> $result = $query->execute();
> $sleepingDrugsList = array();
> /** @var $drug Tx_Latourrisk_Domain_Model_SleepingDrug */
> $drug = NULL;
> foreach ($result as $key => $drug) {
> $sleepingDrugsList[$drug->getUid()] = $drug->getDrugName();
> }
>
> I did that in the controller and I then assign the $sleepingDrugsList
> array to the current view.
>
> Is that the right way to load a value objects list?
>
> Cheers
If you really need to create lists of value object wouldn't they
actually be entities?
Usually when I need to display 'value objects' without the relation to
an object I approach them as being entities. So having a repository
doesn't harm.
It is possible to simply create a repository for your value objects.
Currently working on an order form with dynamic properties (first
approached as value objects). Finally my end model looks like:
OrderForm - 1:n - OrderOptions
Order - 1:n - OrderedOptions - 1:1 - OrderOptions
Does coming to a use of both entities (OrderOptions) as well as value
objects (OrderedOptions).
Hope this helps you!
Henjo
More information about the TYPO3-project-typo3v4mvc
mailing list