[TYPO3-mvc] Model object tree building with Tx_Extbase_Persistence_ObjectStorage property

Claus Fassing claus at fassing.eu
Fri Oct 1 18:09:58 CEST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Franz,

Am 27.09.2010 23:32, schrieb Franz Koch:
> Hey Claus,
> 
>>> Give the following a try in your controllers "form" action (so the
>>> action rendering the initial form, not the one responsible to process
>>> submitted form data):
>>>
>>> if (!$entry->getCompany()->getContact()->count()) {
>>>      $dummyPerson = $this->objectManager->getObject('Person');
>>>      $entry->getCompany()->addContact($dummyPerson);
>>> }
>>
>> The objectManager don't contain any object. So I just try this.
>>
>> if (!$entry->getCompany()->getContact()->count()) {
>>       $contact = t3lib_div::makeInstance('Tx_Myext_Domain_Model_Person');
>>    $entry->getCompany()->addContact($contact);
>> }
> 
> The line above should actually be:
> $dummyPerson =
> $this->objectManager->getObject('Tx_YourExt_Domain_Model_Person');
> 
> I thought that might have been clear - sorry for that. But using
> t3lib_div::makeInstance is also fine for now, because the objectManager
> currenty only does the same thing. But to be better compatible to FLOW3
> and probably make use of upcoming features like "mixins" I personally
> tend to use the objectManager instead where available.
> 
>> Looks from debugging view that company now contain a person object.
> 
> correct - that was intended.
> 
>>> In your template you iterate over the person(s) then:
>>>
>>> <f:for each="{company.contact}" as="contact">
>>>      <f:form.textbox property="company.contact.{contact.uid}.forename"
>>> id="forename"/>
>>>      <f:form.textbox property="company.contact.{contact.uid}.lastname"
>>> id="lastname"/>
>>> </f:for>
>>
>> But in the view company.contact is empty, no iteration
> 
> yes sorry - I got a bit confused by the template and thought the company
> object might be available directly. But in this case you have to use
> {entry.company.contact} in the for loop of course.
> 
>>> Something like that should/could work - not tested though. If it's not
>>> working by assigning this properties, you have to take care of the
>>> correct form names yourself like this:
>>>
>>> <f:form.textbox name="entry[company][contact][{contact.uid}][forname]"
>>> value="{contact.forname} id="forename"/>
>>
>> and no contact.uid available oO
> 
> Ihat might indeed become a problem, because the empty/newly created
> contact doesn't have a uid set. I wasn't sure if it's returning NULL or
> 0 - but I think it's NULL - so we might need to make this a bit more
> complex using a condition - so give this a try:
> 
> <f:for each="{entry.company.contact}" as="contact"><f:alias
> map="{contactId:'{f:if(condition:contact.uid, then:contact.uid,
> else:0)}'}">   
>     <f:form.textbox property="company.contact.{contactId}.forename"
> id="forename"/>
>     <f:form.textbox property="company.contact.{contactId}.lastname"
> id="lastname"/>
> </f:alias>
> </f:for>

It is working now. I use your loop except the map.

<f:for each="{entry.company.contact}" as="contact">
	<f:form.textbox property="company.contact.0.forename" id="forename"
value="{contact.forename}"/>
	<br />

  <f:form.textbox property="company.contact.0.lastname" id="lastname"
value="{contact.lastname}"/>
  <br />
</f:for>

As I mention before contact.uid is uninitialized until persisting,
therefore I don't need the condition.

And with value="{contact.forename}" I don't loosing the value after
error redirect.

Thank you,

Claus

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMpgfVAAoJELsIv+audObfOGgIAJO5+LYPPvutVfv9Ea7KyCSO
tvSjDtOPeW0cQYALQ9nDvoGkgv60l3Pxst8H8M5HRyrfCw5Ht7yCW1RVu3LioXlU
nPGmwpc2fImsciIRamRE4iaa3we7eLCO5MAhGaevYs9fmFVw7K43FbcQxkOFwj6p
09m01tdpjo7rpUVZcts/u3Cl4xK3uHZe0I0HJSWMFtJqBEbc/DhYHBwwAa68Mudz
oO90f5Vs81w6n5I28a13AWlfp9C6Kw2J1NuTEGPq9rTB3OBicmfCxPJM8Odk8XnG
g8lA48/Ja68lE8tnGbUAONGUvcNYznAhYf2guUNOonAfaGUajivgES22vE41Z1o=
=Gi/k
-----END PGP SIGNATURE-----


More information about the TYPO3-project-typo3v4mvc mailing list