[TYPO3-mvc] createAction: get uid of the new object

Christian Essl essl at incert.at
Fri Sep 30 11:33:15 CEST 2011


Hi,

After creating a new Object with a createAction I want to redirect the user to the new object's detail page. Of course I can't know the newly created object. So I do a workaround and look up the uid by the objects alias (which is unique):

                /**
                * action create
                *
                * @param $newLehrgang
                * @return void
                */
                public function createAction(Tx_Extension_Domain_Model_Lehrgang $newLehrgang) {
                               $this->lehrgangRepository->add($newLehrgang);

                               $lehrgang = $this->lehrgangRepository->findOneByAlias($newLehrgang->getAlias());
                               $this->redirect('show', 'Lehrgang', NULL, array('lehrgang' => $lehrgang->getUid()));
                }

But the object $lehrgang remains empty and I can't access the uid. When I prefill the table via the backend with the the values and try to call the createAction again, it's working.
So this behavior suggests, that at the time, I want to fill $lehrgang with the previously added $newLehrgang object, the $newLehrgang object _is not in the database yet_. Even tough, the add()-query is called before I want to get the newly set object... Does extbase somehow delay the add-query for later?

Mit freundlichen Grüßen,

Christian Eßl
Certified TYPO3 Integrator / Mobile Web Developer

INCERT eBusiness
Leonfeldnerstrasse 328
A-4040 Linz
W: www.incert.at



More information about the TYPO3-project-typo3v4mvc mailing list