用于创建 parent/child 记录关系的 DataHandler 结构
DataHandler structure for creating parent/child record relations
我正在尝试使用 TYPO3 的 DataHandler 数据结构(使用 TYPO3 v7 测试)创建嵌套记录结构。然而,关系并未按预期创建。考虑以下数据结构:
$data = array(
'sys_category' =>
array(
'NEW_1' =>
array(
'title' => 'Category 1',
'pid' => $pid,
),
'NEW_2' =>
array(
'title' => 'Category 3',
'pid' => $pid,
),
'NEW_3' =>
array(
'title' => 'Category 2',
'pid' => $pid,
),
'NEW_4' =>
array(
'title' => 'Category 1.1',
'pid' => $pid,
'parent' => 'NEW_1',
),
'NEW_5' =>
array(
'title' => 'Category 1.2',
'pid' => $pid,
'parent' => 'NEW_1',
),
'NEW_6' =>
array(
'title' => 'Category 3.1',
'pid' => $pid,
'parent' => 'NEW_2',
),
),
);
这在数据库中给出了以下结果:
uid title parent
1 Category 1 0
2 Category 3 0
3 Category 2 0
4 Category 1.1 0
5 Category 1.2 0
6 Category 3.1 0
注意所有 "parent" 字段的“0”值。为什么 "NEW_*" 值没有被解释为数据结构中设置的 "parent" 字段?
据我所知,只检查 "NEW" 关键字的 pid 值。
但是您也可以使用一些包含的挂钩来启用 "parent" 的分配。
编辑:
我指的是 TYPO3\CMS\Core\DataHandling\DataHandler::process_datamap()
如上评论所述,TYPO3 6.2 和 7.6 之间情况发生了变化。区别在于\TYPO3\CMS\Core\DataHandling\DataHandler::processRemapStack()
。从 TYPO3 7.6 开始,它会检查 "NEW*" 占位符是否包含短破折号 (_
)。如果是,则占位符在该字符上拆分,字符串的第一部分被认为是相关的 table 名称。
这是与之前相比的变化,之前的短破折号没有特殊含义。实际上,文档中提到了使用低破折号的示例。
所以上面的代码只需要从所有占位符中删除低破折号就可以正常工作。
我正在尝试使用 TYPO3 的 DataHandler 数据结构(使用 TYPO3 v7 测试)创建嵌套记录结构。然而,关系并未按预期创建。考虑以下数据结构:
$data = array(
'sys_category' =>
array(
'NEW_1' =>
array(
'title' => 'Category 1',
'pid' => $pid,
),
'NEW_2' =>
array(
'title' => 'Category 3',
'pid' => $pid,
),
'NEW_3' =>
array(
'title' => 'Category 2',
'pid' => $pid,
),
'NEW_4' =>
array(
'title' => 'Category 1.1',
'pid' => $pid,
'parent' => 'NEW_1',
),
'NEW_5' =>
array(
'title' => 'Category 1.2',
'pid' => $pid,
'parent' => 'NEW_1',
),
'NEW_6' =>
array(
'title' => 'Category 3.1',
'pid' => $pid,
'parent' => 'NEW_2',
),
),
);
这在数据库中给出了以下结果:
uid title parent
1 Category 1 0
2 Category 3 0
3 Category 2 0
4 Category 1.1 0
5 Category 1.2 0
6 Category 3.1 0
注意所有 "parent" 字段的“0”值。为什么 "NEW_*" 值没有被解释为数据结构中设置的 "parent" 字段?
据我所知,只检查 "NEW" 关键字的 pid 值。 但是您也可以使用一些包含的挂钩来启用 "parent" 的分配。
编辑: 我指的是 TYPO3\CMS\Core\DataHandling\DataHandler::process_datamap()
如上评论所述,TYPO3 6.2 和 7.6 之间情况发生了变化。区别在于\TYPO3\CMS\Core\DataHandling\DataHandler::processRemapStack()
。从 TYPO3 7.6 开始,它会检查 "NEW*" 占位符是否包含短破折号 (_
)。如果是,则占位符在该字符上拆分,字符串的第一部分被认为是相关的 table 名称。
这是与之前相比的变化,之前的短破折号没有特殊含义。实际上,文档中提到了使用低破折号的示例。
所以上面的代码只需要从所有占位符中删除低破折号就可以正常工作。