[TYPO3-mvc] FLUID :: how can you access properties of m:n related objects?

Sebastian Schreiber me at schreibersebastian.de
Thu Nov 3 10:35:29 CET 2011


Am 03.11.2011 10:28, schrieb Henjo Hoeksma:
> Hi Roland,
>
> you can use an iterator for this
>
> <f:for each="{produkts}" as="produkt" iteration="produktIterator">
> <f:if condition="{produktIterator.isFirst}">
> ...
>
> See the Fluid Viewhelper for if on the possibilities you have.
>
> Kind regards,
>
> Henjo
>
> Problems are small because we learned how to deal with them.
> Problems are big because we need to learn how to deal with them.
>
>
> On Thu, Nov 3, 2011 at 09:46, Roland<most.wanted at gmx.at>  wrote:
>
>> hi everybody,
>>
>> in the domain model there is an object "Produkt" with an relation
>> "zulassungen", which is m:n related to the object "Zulassung".
>>
>> now i want to output the property "name" of the first related "Zulassung"
>> of the "Produkt"s in my FLUID template list view.
>>
>> QUESTION: how can i access the name of the first related "Zulassung" of an
>> "Produkt" in my FLUID template?
>>
>> i tried this:
>>
>> --- quote ---
>>
>> <ul>
>> <f:for each="{produkts}" as="produkt">
>>         <li>{produkt.name} - {produkt.zulassungen.0.name}</**li>
>> </f:for>
>> </ul>
>>
>> --- /quote ---
>>
>> ...but only the "name" of the "Produkt"s is outputted.
>>
>> when i debug {produkt} via the debug viewhelper within the for viewhelper,
>> something like this is what is outputted for each "Produkt":
>>
>> --- quote ---
>>
>> |Object:
>>
>> Tx_Extbase_Persistence_**ObjectStorage Object
>> (
>>     [warning:Tx_Extbase_**Persistence_ObjectStorage:**private] =>  You
>> should never see this warning. If you do, you probably used PHP array
>> functions like current() on the Tx_Extbase_Persistence_**ObjectStorage.
>> To retrieve the first result, you can use the rewind() and current()
>> methods.
>>     [storage:protected] =>  Array
>>         (
>>             [**0000000007f694db0000000036e567**48] =>  Array
>>                 (
>>                     [obj] =>  Tx_Gebroprodukte_Domain_Model_**Zulassung
>> Object
>>                         (
>>                             [name:protected] =>  OTC
>>                             [uid:protected] =>  2
>>                             [_localizedUid:protected] =>  2
>>                             [_languageUid:protected] =>  0
>>                             [pid:protected] =>  85
>>
>> [_isClone:Tx_Extbase_**DomainObject_**AbstractDomainObject:private] =>
>>
>> [_cleanProperties:Tx_Extbase_**DomainObject_**AbstractDomainObject:private]
>> =>  Array
>>                                 (
>>                                     [name] =>  OTC
>>                                     [uid] =>  2
>>                                     [pid] =>  85
>>                                 )
>>
>>                         )
>>
>>                     [inf] =>
>>                 )
>>
>>             [**0000000007f694c50000000036e567**48] =>  Array
>>                 (
>>                     [obj] =>  Tx_Gebroprodukte_Domain_Model_**Zulassung
>> Object
>>                         (
>>                             [name:protected] =>  Freihand
>>                             [uid:protected] =>  3
>>                             [_localizedUid:protected] =>  3
>>                             [_languageUid:protected] =>  0
>>                             [pid:protected] =>  85
>>
>> [_isClone:Tx_Extbase_**DomainObject_**AbstractDomainObject:private] =>
>>
>> [_cleanProperties:Tx_Extbase_**DomainObject_**AbstractDomainObject:private]
>> =>  Array
>>                                 (
>>                                     [name] =>  Freihand
>>                                     [uid] =>  3
>>                                     [pid] =>  85
>>                                 )
>>
>>                         )
>>
>>                     [inf] =>
>>                 )
>>
>>         )
>>
>>     [isModified:protected] =>
>> )
>>
>> |
>> --- / quote ---
>> ______________________________**_________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc@**lists.typo3.org<TYPO3-project-typo3v4mvc at lists.typo3.org>
>> http://lists.typo3.org/cgi-**bin/mailman/listinfo/typo3-**
>> project-typo3v4mvc<http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc>
>>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
I would write a dedicated viewhelper or getter in your DomainModel to 
retrieve the first object.
For the getter approach you can write something like that:

public function getFirstZulassung() {
$object = $this->getZulassungen() // Or whatever
// Maybe you can drop the instanceof validation
if($object instanceof Tx_Extbase_Persistence_ObjectStorage) {
             $object->rewind();
             if($object->valid()) {
                 return $object->current();
             }
      }
}

-- 
Sebastian Schreiber
(Medieninformatiker B.Sc.)
(TYPO3 Certified Integrator)

Schanzenstraße 27, Schlosserei 4
D-51063 Köln

T  0221 677 88 541
M  0176 431 05 790

Skype schreibersebastian.de

me at schreibersebastian.de
www.schreibersebastian.de

Steuernummer: 217 / 5269 / 4675



More information about the TYPO3-project-typo3v4mvc mailing list