How to get identifier after saving ExtBase model?

After creating the model and adding it to the repository, I want to have a new identifier for different purposes (creating mail, updating other fields outside the Extbase world)

$page = t3lib_div::makeInstance('Tx_MyExt_Domain_Model_Page');
$page->setTitle('Hello World');
$this->pageRepository->add($page);

At this point, I $pagehave not yet received the identifier, uid is null.

$page->getUid(); // returns null

When will it work? And how can I get at runtime?

+3
source share
2 answers

ExtBase "". , persistence (//) , (, ). , , , , . , $persistenceManager->persistAll(), , -. , $page UID $page->getUid() null. , .

, - ExtBase/MVC. , null, UID , .

, - , , , , UID. , Controller, , , , , , / .

, , . , :

$this->view->assign('page', $page);

, , :

<f:link.action action="show" arguments="{page:page}">
    See this page object
</f:link.action>

show :

public function showAction(Tx_MyExt_Domain_Model_Page $page) {
    // Do whatever you need to show the page in the `Show.html` template
}

. , , , - , .

( , TYPO3 - . TYPO3 , php. )

+3

,

#TYPO3 4.x
$persistenceManager = $this->objectManager->create('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();

#TYPO3 6.x
$persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
$persistenceManager->persistAll();
+1

All Articles