未在流体形式中列出的属性在提交后被覆盖
Properties that were not listed in fluid-form overwritten after submit
在我的 extbase 6.2 扩展中(使用扩展构建器构建)我有:
- 一个
appointment
有
- 一个
lawyer
有
- 专业化(在此示例中称为
expertises
)。
在我的表单中,我只想编辑 expertises
,但每次我点击提交时,我的 lawyer
的属性都被清空,除了 expertises
- 这些工作,甚至他们的价值观是正确的。
当我在流体中调试对象时,律师在那里,一切都是正确的。
这是我在流体形式中唯一写下单词 "lawyer".
的地方
<f:for each="{appointment.lawyer.expertises}" as="expertise" iteration="i">
<f:form.checkbox property="lawyer.expertises.{i.index}.checked" value="1"/>
<f:for each="{expertise.subExpertises}" as="subExpertise" iteration="j">
<f:form.checkbox property="lawyer.expertises.{i.index}.subExpertises.{j.index}.checked" value="1"/>
</f:for>
</f:for>
通常我的 appointment
属性不会因为我没有为它们编写表单输入字段而被覆盖。
那么为什么 appointment.lawyer
的属性会被覆盖?我该如何避免这种情况发生?
不幸的是,我不知道 TYPO3 正在做什么以便从我的表单构建一个对象,所以任何关于这方面的提示也将不胜感激:)
编辑相关元素的属性并不容易。
TYPO3 在您的案例中所做的是将原始相关 lawyer
记录(以及原始 expertises
)从 appointment
对象中分离出来,并创建一个新记录,这就是为什么您认为其他属性被清空的原因。您还会看到,如果您在列表视图中查找元素,每次保存时都会有越来越多的元素。原因是表单不会自动生成 lawyer
和 expertises
的 uid,所以 TYPO3 认为这些是新对象。
我知道一个解决方案(如果有人知道更好的,请分享)但是你需要阅读整个描述:
您必须在表单中为每个相关对象手动添加 uid 字段。假设您的表单有 name="appointment"
<f:form.hidden name="appointment[lawyer][__identity]" value="{appointment.lawyer.uid}" />
<f:form.hidden name="appointment[lawyer][expertises][{i.index}][__identity]" value="{expertise.uid}"/>
您还必须为子属性执行此操作。
重要!
这样用户也可以操纵 id 并修改他不应该访问的对象,因此您必须在保存之前检查关系。为此,您可以使用域对象的 _getCleanProperty('xx')
方法来获取它的原始数据。
if ($appointment->getLawyer()->getUid() != $appointment->_getCleanProperty('lawyer')->getUid()) {
die('error');
}
你当然需要检查所有可以这样操作的关系。
在我的 extbase 6.2 扩展中(使用扩展构建器构建)我有:
- 一个
appointment
有- 一个
lawyer
有- 专业化(在此示例中称为
expertises
)。
- 专业化(在此示例中称为
- 一个
在我的表单中,我只想编辑 expertises
,但每次我点击提交时,我的 lawyer
的属性都被清空,除了 expertises
- 这些工作,甚至他们的价值观是正确的。
当我在流体中调试对象时,律师在那里,一切都是正确的。
这是我在流体形式中唯一写下单词 "lawyer".
<f:for each="{appointment.lawyer.expertises}" as="expertise" iteration="i">
<f:form.checkbox property="lawyer.expertises.{i.index}.checked" value="1"/>
<f:for each="{expertise.subExpertises}" as="subExpertise" iteration="j">
<f:form.checkbox property="lawyer.expertises.{i.index}.subExpertises.{j.index}.checked" value="1"/>
</f:for>
</f:for>
通常我的 appointment
属性不会因为我没有为它们编写表单输入字段而被覆盖。
那么为什么 appointment.lawyer
的属性会被覆盖?我该如何避免这种情况发生?
不幸的是,我不知道 TYPO3 正在做什么以便从我的表单构建一个对象,所以任何关于这方面的提示也将不胜感激:)
编辑相关元素的属性并不容易。
TYPO3 在您的案例中所做的是将原始相关 lawyer
记录(以及原始 expertises
)从 appointment
对象中分离出来,并创建一个新记录,这就是为什么您认为其他属性被清空的原因。您还会看到,如果您在列表视图中查找元素,每次保存时都会有越来越多的元素。原因是表单不会自动生成 lawyer
和 expertises
的 uid,所以 TYPO3 认为这些是新对象。
我知道一个解决方案(如果有人知道更好的,请分享)但是你需要阅读整个描述:
您必须在表单中为每个相关对象手动添加 uid 字段。假设您的表单有 name="appointment"
<f:form.hidden name="appointment[lawyer][__identity]" value="{appointment.lawyer.uid}" />
<f:form.hidden name="appointment[lawyer][expertises][{i.index}][__identity]" value="{expertise.uid}"/>
您还必须为子属性执行此操作。
重要!
这样用户也可以操纵 id 并修改他不应该访问的对象,因此您必须在保存之前检查关系。为此,您可以使用域对象的 _getCleanProperty('xx')
方法来获取它的原始数据。
if ($appointment->getLawyer()->getUid() != $appointment->_getCleanProperty('lawyer')->getUid()) {
die('error');
}
你当然需要检查所有可以这样操作的关系。