[TYPO3-mvc] Get last id

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jan 17 14:31:31 CET 2011


Hey,

> How to get last inserted id.
>
> Is there a method in extbase simillar to mysql_insert_id ??
>
> I`ve used it but it gives me a strange result.
> Id of last inserted id is 14 and i get 881.
>
> Any ideas ?

you can't. Objects are persisted at the end of the extensions lifecycle 
and in a random order. If you need the uid of a new object for further 
processing you first have to trigger persistence manually, then your 
objects themselves will contain the correct UID already and you don't 
have to grab it from MySql.

// add the object to the repository
$yourRepository->add($someNewObject);

// then persist everything
$persistenceManager = 
$this->objectManager->get('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();

// now your object has a valid identity/uid
var_dump ($someNewObject->getUid());

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list