[TYPO3-mvc] Persistence Manager serve for what

Tim Schoch | GSTALTIG tim.schoch at gstaltig.ch
Fri Oct 14 10:05:15 CEST 2011


Hello Yuth

When you call $persistenceManager->persistAll(); the mutations made to objects in all repositories are persisted (written to the database).
I use this alot, when I need to get the uid of a freshly created object. eg, in a createAction:
createAction ( FooBar $newFoo ) {
  $this->fooBarRepository->add( $newFoo ); // at this point, $newFoo->uid is still NULL
   $persistenceManager->persistAll(); // during persisting, $newFoo will get its uid
  $this->redirect( 'show', NULL, array( 'foo' => $newFoo ) ); // will show your newly created object
}

Without the call to persistAll() the redirection would fail, because $newFoo has no uid at the point the redirection happens.

I hope this helps you.
Tim


More information about the TYPO3-project-typo3v4mvc mailing list