[TYPO3-mvc] Problems on double use of a object in two different objectStorage
Franz Koch
typo3.RemoveForMessage at elements-net.de
Mon Sep 20 09:49:44 CEST 2010
Hey,
> in my helper class i make a clone from the current object now like this:
>
> /**
> * Find a selected Object in a object array by a given uid for forms
> * @param array $arr The Object array
> * @param int $uid The uid
> * @return array $arr The updated array
> */
> Public Function findSelectedObjectinArrayByUid($arr,$uid){
> if(is_array($arr)){
> $i=0;
> foreach ($arr as $obj) {
> if($obj->getUid()==$uid) {
> $arr[$i] = clone $obj;
> $arr[$i]->setFormselected("selected='selected'");
> }
> $i++;
> }
> }
> return $arr;
> }
>
> On the clone in filled up the property. That resolve my problem. But is
> this right way?
as long as you don't need persistence for your stations/objects, you
should always clone them in order to cut the connection to the
persistence layer - otherwise changes made to these objects will
automatically be stored in the DB (as long as the modified properties
relate to TCA columns). While this might work for you now, the way you
deal with the form seems in general wrong to me from an OOP point of view.
You have to render a form - right? Then you might need a formObject
that's reflecting the possible formFields and also takes care of
validation by setting according annotations for it's properties.
You pass this formObject to the Fluid formViewHelper and assign the
according properties to your formFields. Extbase is doing all the magic
of mapping the values of the form fields to the formObject automatically
then. It also does automatically know which station is selected, as this
is stored inside the formObject and does not have to be stored in the
stationObject.
You could also store the form values inside a custom array instead of a
object and use it's values to see which fields are selected - this
should work too up to a certain degree. But using a object is the
recommended way in your case I think.
If you need multiStepForms, there are some solutions/concepts available
on this list.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list