[TYPO3-mvc] f:for inside f:for ?

Sören Kracker s.kracker at kopfstand-mail.de
Thu Feb 16 09:06:40 CET 2012


You would put {person.logEntry} in your list.html. Btw: afaik it is 
usual to call the ObjectStorage like the plural of the model ($log -> 
$logs).
Then you can access the log using something like {log.myvar}

Do you have set up a function in your model too?
     /**
      * Returns the logs
      *
      * @return 
Tx_Extbase_Persistence_ObjectStorage<Tx_DkmFolkekirkenindmeld_Domain_Model_Log> 
$logs
      */
     public function getLogs() {
         return $this->logs;
     }

You don't need to instantiate anything of the logs in your controller. 
This is handled by extbase.
But you have to setup your TCA correctly.
For example in your TCA of person you have an entry for "logs" or 
"logEntry" with that config:
'config' => array(
         'type' => 'inline',
         'foreign_table' => 'tx_abc_domain_model_log',
         'foreign_field' => 'person', #or like you've called the field 
for the relation

And in your person model you need this:
     /**
      * __construct
      *
      * @return void
      */
     public function __construct() {
         //Do not remove the next line: It would break the functionality
         $this->initStorageObjects();
     }

     /**
      * Initializes all Tx_Extbase_Persistence_ObjectStorage properties.
      *
      * @return void
      */
     protected function initStorageObjects() {
         /**
          * Do not modify this method!
          * It will be rewritten on each save in the extension builder
          * You may modify the constructor of this class instead
          */
         $this->logs = new Tx_Extbase_Persistence_ObjectStorage();
     }

This is all created by the extension builder when you setup your domain 
objects. It's a good place to begin with. You'll see how extbase handles 
things.

I hope this will help.

Sören

Am 15.02.2012 18:55, schrieb Stig Nørgaard Færch:
>>>>> I have a Log domain model linked to a Person domain model.
>>>>> So a Person can have multiple Logs attached.
>>>>>
>>>>> In the list view of the Person I would like to be able to fetch the
>>>>> belonging log entries.
>>>>> And it would be even better if I could decide which ones by a custom
>>>>> query. If not, I guess I could limit them by fluid ifs...
>>>>>
>>>>> But, I'm not sure exactly how to do this. Still newbie.
>>>>> But I did this - which doesn't work:
>>>>>
>>>>> **List.html:
>>>>> <f:for each="{persons}" as="person">
>>>>> <tr>
>>>>> <td><f:link.action action="show" arguments="{person : person}">
>>>>> {person.fullName}</f:link.action></td>
>>>>> <td>
>>>>> <f:for each="{person : logs}" as="log">
>>>>> {log.actionName}<br/>
>>>>> </f:for>
>>>>> </td>
>>>>> </tr>
>>>>> </f:for>
>
> > It would be an ObjectStorage of the Logs.
> > You would define that in your model, e.g.:
>
> Okay, in my Person model I have:
>     /**
>      * logEntry
>      *
>      * @var 
> Tx_Extbase_Persistence_ObjectStorage<Tx_DkmFolkekirkenindmeld_Domain_Model_Log>
>      */
>     protected $logEntry;
>
> So what should I put in the list.html template?
> And what should go in my listAction mehtod?
> Would that be?:
> $logEntry = 
> t3lib_div::makeInstance('Tx_DkmFolkekirkenindmeld_Domain_Model_Log');
> $this->view->assign('logs', $logEntry);
>
> and then call {person.logEntry} or {person : logEntry} or {logEntry} 
> in list.html?? :-)
>
> /Stig
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


More information about the TYPO3-project-typo3v4mvc mailing list