[FLOW3-general] Mapping and adding objects - problem with properties
Dawid Pacholczyk
dpacholczyk at gmail.com
Thu Sep 1 00:08:22 CEST 2011
Thanks for the effort but it`s the same :(
W dniu 2011-08-31 23:37, Ferdinand Kuhl pisze:
> Ah! OneToMany is the key. Here it is a bit different. In your initialize you
> have to:
>
> /**
> * Initialize createAction
> *
> * @return void
> */
> public function initializeCreateAction() {
> $this->arguments['newUser']-
>> getPropertyMappingConfiguration()->forProperty('birthdate')-
>> setTypeConverterOption('TYPO3\FLOW3\Property\TypeConverter\DateTimeConverter',
> \TYPO3\FLOW3\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
> 'd-m-Y');
>
> $this->arguments['newUser']->getPropertyMappingConfiguration()-
>> forProperty('addresses')-
>> setTypeConverterOption('TYPO3\FLOW3\Property\TypeConverter\PersistentObjectConverter',
> \TYPO3\FLOW3\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
> true);
> # $this->arguments['newUser']->getPropertyMappingConfiguration()-
>> setTargetTypeForSubProperty('addresses',
> 'My\Package\Domain\Model\Address');
> $this->arguments['newUser']-
>> getPropertyMappingConfiguration()-
>> allowModificationForSubProperty('addresses');
> $this->arguments['newUser']-
>> getPropertyMappingConfiguration()-
>> allowModificationForSubProperty('addresses.0');
> }
>
> (see the 'addresses.0'!)
>
> And for collection-arguments you have to add (at least) a constructor to
> your entity:
>
> public function __construct() {
> $this->addresses = new \Doctrine\Common\Collections\ArrayCollection();
> }
>
> Another try, another luck!
>
> Dawid Pacholczyk wrote:
>
>> Guys I`ve uploaded my actual userController
>> https://sourceforge.net/projects/flow3training/files/
>>
>> pls if you can have a look
>>
>> My problem is that. I`m creating Address object in initializeCreateAction
>>
>> What do I need to do in createAction ? I want to add address to the
>> collection, add to Address object reference to the user and save the
>> Address.
>>
>> I`m rly in the corner :(
>>
>> Best regards,
>> Dawid Pacholczyk
>>
>> W dniu 2011-08-31 22:06, Dawid Pacholczyk pisze:
>>> THe relation is @OneToMany
>>>
>>> One user many Addresses
>>>
>>> I have and ArrayCollection. I`ve managed to remap data from form as an
>>> object. Now I need to add it to collection
>>>
>>> #1: Catchable Fatal Error: Argument 1 passed to
>>> Doctrine\Common\Collections\ArrayCollection::__construct() must be an
>>> array, object given, called in
>>> D:
> \wamp\www\directory\Packages\Framework\Doctrine\Classes\ORM\UnitOfWork.php
>>> on line 416 and defined in
>>> D:
> \wamp\www\directory\Packages\Framework\Doctrine\Classes\Common\Collections\ArrayCollection.php
>>> line 46
>>>
>>> but I`m getting further and further thanks to you :)
>>>
>>> W dniu 2011-08-31 21:50, Ferdinand Kuhl pisze:
>>>> The lines I suggested you do work for me on many use cases.
>>>>
>>>> What kind of relation? OneToOne, OneToMany, ManyToOne or ManyToMany?
>>>>
>>>> Dawid Pacholczyk wrote:
>>>>
>>>>> I went this way
>>>>>
>>>>>
>>>>> $this->arguments['newUser']->getPropertyMappingConfiguration()-
>>>>> forProperty('address')-
>>>>>
> setTypeConverterOption('TYPO3\FLOW3\Property\TypeConverter\PersistentObjectConverter',
>>>>>
>>>>>
>>>>
> \TYPO3\FLOW3\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
>>>>
>>>>> true);
>>>>>
>>>>> $this->arguments['newUser']->getPropertyMappingConfiguration()-
>>>>> setTargetTypeForSubProperty('address',
>>>>> 'My\Package\Domain\Model\Address');
>>>>>
>>>>> but I`m getting
>>>>>
>>>>> #1297759968: Exception while property mapping at property path
>>>>> "address":Creation of objects not allowed. To enable this, you need to
>>>>> set the PropertyMappingConfiguration Value
>>>>> "CONFIGURATION_CREATION_ALLOWED" to TRUE
>>>>>
>>>>> W dniu 2011-08-31 19:06, Ferdinand Kuhl pisze:
>>>>>> No Problem! I'm sure we all had similar experiences before. ;)
>>>>>>
>>>>>> What kind of relation?
>>>>>>
>>>>>> Basically you will have to do the following:
>>>>>>
>>>>>> FLUID-Form:
>>>>>>
>>>>>> <f:form.textfield property="address.city" />
>>>>>> <f:form.textfield property="address.zip" />
>>>>>> ...
>>>>>>
>>>>>> And in your Controller:
>>>>>>
>>>>>> public function initializeCreateAction() {
>>>>>> $this->arguments['newUser']->getPropertyMappingConfiguration()-
>>>>>>> allowCreationForSubProperty('address');
>>>>>> }
>>>>>>
>>>>>> The rest should Flow3 do for you ;)
>>>>>>
>>>>>> Have a nice evening,
>>>>>> Ferdinand
>>>>>>
>>>>>> Dawid Pacholczyk wrote:
>>>>>>
>>>>>>> OH MY GOD !!!!!!!!!!!!!!!!!!!!
>>>>>>>
>>>>>>> Sorry but I lost 2 days for that :/ I`ve changed the field, I`ve
>>>>>>> changed
>>>>>>> the getter but I had to forget about setter. Thank you Sebastian
>>>>>>>
>>>>>>> Ferdinand big thank you to you too for your time
>>>>>>>
>>>>>>> Guys, what about second question ? I have association with Address
>>>>>>> object and I would like to put in my New.html 3 fields from address
>>>>>>>
>>>>>>> street, city, zip
>>>>>>>
>>>>>>> They are not User properties but Address properties. How can I in
>>>>>>> initial method receive values and combine them to Address object and
>>>>>>> invoke setAddress ?
>>>>>>>
>>>>>>> Best regards,
>>>>>>> Dawid Pacholczyk
>>>>>>>
>>>>>>> W dniu 2011-08-31 18:38, Sebastian Kurfürst pisze:
>>>>>>>> Hey,
>>>>>>>>
>>>>>>>>> public function setAge($birthdate) {
>>>>>>>>> $this->birthdate = $birthdate;
>>>>>>>>> }
>>>>>>>>
>>>>>>>> That's the error :-) It must be "public function setBirthdate".
>>>>>>>>
>>>>>>>> Greets,
>>>>>>>> Sebastian
>>>>>>>>
>>>>>>
>>>>
>>>
>
More information about the FLOW3-general
mailing list