[TYPO3-mvc] Problems on double use of a object in two different objectStorage

Manfred Rutschmann manfred.rutschmann at revier.de
Mon Sep 20 07:26:46 CEST 2010


Hi list,

i get some few objects of the same type from a repository. At second i had
a session where some relations to this object type are stored. I need to
create my own select with options for ajax output and let run my objects
throug a function that find the object in my array that is related to the
one in my session. If i have a hit i set a property. I need this for a
plugin which is located on every typo3 site where the user inputs are
stored. In this case no problems. But in a special case i use one object
type, called station, double on the form. The first is the startstation and
the second is the endstation. The process for the startstaion looks fine,
but the secondstation has stored the edited object of the startstation. So
here a little bit of code:

In my model i had this ones:

/**
 * formselected
 * @var string
 * @dontvalidate 
 */
protected $formselected;

/**
 * Set the form selected value
 * @param string $formselected
 */
public function setFormselected($param_formselected) {
    $this->formselected = $param_formselected;
}
/**
 * Returns the formselected value.
 * @return string
 */
public function getFormselected() {
    return $this->formselected;
}	


In my controller i get the array with all needed stations from repo:

$stationList = $this->stationRepository->findByLandAndFahrzeugkategorie(
			$arguments['Land'], 
			$arguments['Fahrzeugkategorie']
);

I get my needed array back. So now comes the tricky. I give the whole array
to a helper function. The uid of the selected object in the form is as
second argument attached too:


$stations =
$this->helper->findSelectedObjectinArrayByUid($stationList,$arguments['Station']);
$this->view->assign('stations',$stations);

$endstations =
$this->helper->findSelectedObjectinArrayByUid($stationList,$arguments['Endstation']);
$this->view->assign('endstations',$endstations);

And here comes the little helper:

/**
 * 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){
	print_r($arr);
	if(is_array($arr)){
		$i=0;
		foreach ($arr as $obj) {
			if($obj->getUid()==$uid) {
				$arr[$i]->setFormselected("selected='selected'");
			}
			$i++;
		}
	}
	return $arr;
}


So here comes the raw output form the $stations:
http://pastebin.com/4egYUcq8
As you can see is the first object with the uid 31 with the property
formselected filled. So far so good. 

Now we take a look at the $endtstaions output:
http://pastebin.com/fxzW5XDX

Here you can see that the first object is at times filled on the property
and in addition the object 7 also (uid 38).

So i have to use different object storages, but the in the summary it is
the same. I have to use not the original objects but an static instance or
copy that can i manipulate extra for each array...

But i have no idea to do this. Has anybody some ideas to me?

Thanks and regards
Manfred


More information about the TYPO3-project-typo3v4mvc mailing list