在 hook processDatamap_afterDatabaseOperations 中获取新记录的 uid [英] Get uid of new record in hook processDatamap_afterDatabaseOperations
问题描述
创建新的数据库记录时,TYPO3 为它们分配一个临时 UID,如下所示:NEW56fe740dd5a455.64167468
.当记录插入数据库时,记录获得其真实的 UID.
When creating new database records, TYPO3 assigns them a temporary UID, which looks like this: NEW56fe740dd5a455.64167468
. The record gets its real UID when it is inserted into the database.
在上面的钩子中,记录已经插入到数据库中,所以它分配了一个数字 uid.如何从给定的临时 UID 中获取该 uid?
In the above hook, the record is already inserted into the database, so it has a numerical uid assigned. How do I get that uid from a given temporary UID?
推荐答案
好的,找到了.hook-method 的第四个参数是 datahandler 对象,它有一个属性 substNEWwithIDs
,一个关联数组,将临时 UID 映射到真实 UID.
Ok, found it. The fourth parameter of the hook-method is the datahandler object, which has a property substNEWwithIDs
, an associative array mapping temporary UIDs to the real UIDs.
可以像这样使用它:
public function processDatamap_afterDatabaseOperations($action, $table, $uid, $datahandler)
{
if (GeneralUtility::isFirstPartOfStr($uid, 'NEW')) {
$uid = $datahandler->substNEWwithIDs[$uid];
}
// Do something with the UID
}
这篇关于在 hook processDatamap_afterDatabaseOperations 中获取新记录的 uid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!