Hi Felix, hier ein Beispiel Variante zwei. Der code wird warscheinlich fehler enthalten. (da ich ihn jetzt nur mal so hier rein tippe) und mir verschidene codeschnipsel aus meinen eigenen codebasen zusammen copiert habe. (deswegen mag es auch sein das es eine mischung aus 4.5 und 6.2 code ist. aber ich denke es ist genug um eine idee davon zu bekommen was ich eigendlich meine.
<!-- hier wird kein Object angegeben (da man ja kein Object Mapped) --> <f:form action="updateHausAndZimmer"> <!-- werte für das haus object --> <f:form.hidden name="haus[uid]" value="{haus.uid}" /> <f:form.textfield name="haus[name]" value="haus.name" /> <!-- werte für das zimmer object --> <f:form.hidden name="zimmer[uid]" value="{zimmer.uid}" /> <f:form.textfield name="zimmer[name]" value="zimmer.name" /> <f:form.submit name="mySaveButton" value="Abspeichern" /> </f:form> <?php /** * update the haus and zimmer * @param array $hausArray haus data array * @param array $zimmerArray the zimmer data array * @return null */ public function updateHausAndZimmerAction($hausArray, $zimmerArray){ // we get data wich could not be validated by Extbase here. // therefor we have to make shure that everything is correct // 1) Validadate that the that the user is allowed to edit the models by checking the ids/access rights! if(!$this->myAccessVerification($hausArray) or !$this->myAccessVerification($zimmerArray)){ $this->errorAction(); } // 2) mapping the array data to models (better do this explicit with properties you konw rather than use a for loop) $hausObject = $this->hausRepository->getByUid($hausArray['uid']); $hausObject->setName($hausArray['name']); $errorArray = new Array(); if(!$this->validateObject($hausObject){ $this->errorAction(); } $zimmerObject = $this->zimmerRepository->getByUid($zimmerArray['uid']); $zimmerObject->setName($zimmerArray['name']); if(!$this->validateObject($zimmerObject){ $this->errorAction(); } // update the changed Object. $this->zimmerRepository->update($zimmerObject); $this->hausRepository->update($hausObject); } /** * Validates an Object against its Model Descriptions @validate Notations * @param object $object the Domain Object to be Validated * @param array $errorArray reference to an Array Holding the Object Errors * @param boolean $addCustomErrors should the addCustomError() function be called if errors exists * @return boolean if the object validates */ protected function validateObject($object, &$errorArray = array(), $addCustomErrors = true){ $errorArray = array(); $className = get_class($object); $validatorResolver = $this->objectManager->get('Tx_Extbase_Validation_ValidatorResolver'); $validatorConjunction = $validatorResolver->getBaseValidatorConjunction($className); $result = $validatorConjunction->isValid($object); if($result === true){ return true; } $errorArray = $validatorConjunction->getErrors(); if($addCustomErrors){ foreach ($errorArray as $property => $error) { $this->addCustomError($property,$error->getMessage(),$error->getCode()); } } return false; } ?> Gruss chris -----Ursprüngliche Nachricht----- Von: typo3-german-boun...@lists.typo3.org [mailto:typo3-german-boun...@lists.typo3.org] Im Auftrag von Chris Wolff - AERTiCKET AG Gesendet: Dienstag, 23. Dezember 2014 10:15 An: Felix Hohlwegler; German TYPO3 Userlist Betreff: Re: [TYPO3-german] Ein Formular mehrere Models Hallo Felix, Extbase kann leider nicht wirklich mit mehreren Models Pro Formular Umgehen! es gibt nur mehrere Hacks um das zu umgehen. a) eine Combi-model HausUndZimmerFormular nur für das formular vorteil: extbase Validierung funktioniert auf dem Model. nachteil: du musst ein Model mehr Pflegen und die Daten im Controller noch mal um Mappen. b) gar kein Model im Formular angeben. Und einfach benannte felder verwenden. Vorteil: es geht einfach. Nachteil: du musst die einfachen variablen/arrays auf das Model Mappen. Und die Validierung sicherstellen. Gruss chris -----Ursprüngliche Nachricht----- Von: typo3-german-boun...@lists.typo3.org [mailto:typo3-german-boun...@lists.typo3.org] Im Auftrag von Felix Hohlwegler Gesendet: Dienstag, 23. Dezember 2014 01:49 An: typo3-german@lists.typo3.org Betreff: [TYPO3-german] Ein Formular mehrere Models Hi Zusammen, ich möchte gerne ein Formular haben bei dem ich zwei Models gleichzeitig anlege und persistiere. also z.B. ich hab ein Formular Haus / Zimmer dann möchte ich im gleichen Formular ein Haus anlegen können und ein Zimmer <f:form action="create" name="newHaus" object="{newHaus}"> und dann hab ich die inputs so: <f:form.textfield name="haus[hausnummer]" class="form-control gettooltip" placeholder="Hausnummer"/> <f:form.textfield name="zimmer[Zimmernummer]" class="form-control gettooltip" placeholder="Zimmernummer"/> der Kontroller sieht dann so aus: public function createAction(\Gebauede\GEB\Domain\Model\Haus $newHaus, \Gebauede\GEB\Domain\Model\Zimmer $newZimmer) { $this->hausRepository->add($newHaus); $this->zimmerRepository->add($newZimmer); $this->redirect('list'); } Das klappt aber nicht ... Fehlermeldung: Required argument "newHaus" is not set. was mache ich falsch? _______________________________________________ TYPO3-german mailing list TYPO3-german@lists.typo3.org http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german _______________________________________________ TYPO3-german mailing list TYPO3-german@lists.typo3.org http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german _______________________________________________ TYPO3-german mailing list TYPO3-german@lists.typo3.org http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german