[TYPO3-mvc] attach on non-object error

Johannes C. Schulz - EnzephaloN IT-Solutions info at enzephalon.de
Mon Mar 5 09:15:51 CET 2012


Hello list

 

Following problem. From a form I generate some "person"-properties. In my
backend "save" controller I try to write them in an person-object. Works
fine if I use setPorperty(foo) but I get an "Call to a member function
attach() on a non-object . Model" error if I use an addProperty. I think
this happens cause I open the person-object by finding it, and not by
accessing it from the parent-object. Here the code-snippet from my
backend-controller:

$persons = $this->request->getArgument('person');
       foreach ($persons as $aid => $person) {
       $personObject = $this->personRepository->findOneByAid($aid);
              if(!empty($person['exchangeticket']))
$personObject->setExchangeticket($person['exchangeticket']);

                    if(!empty($person['passport'])){

                          foreach ($person['passport'] as $passport){

 
$personObject->addPassport($this->passportRepository->findOneByUid($passport
));

                          }

                    }

             }

       }

 

How can I do this in the right way?

Best regards

Johannes



More information about the TYPO3-project-typo3v4mvc mailing list