问题描述
我有一个表单,表示我们的数据库中的 RewardModifier
表。 RewardModifier
hasMany
RewardOption
。
I have a form that represents a RewardModifier
table in our database. That RewardModifier
hasMany
RewardOption
.
我的表单结构如下(图片):
My form is structured like this (image):
因此, RewardModifier
,每个都有许多 RewardOption
项目。
So, the RewardModifier
can have many elements on the page, each with many RewardOption
items.
问题
问题是,用户可以删除此部分形式使用Javascript,基本上从DOM中删除它。当他们这样做,它打破了安全组件,因为POST'ed字段不匹配在页面生成时提供的令牌。
The problem is, that users can delete sections of this form using Javascript, which essentially removes it from the DOM. When they do that, it breaks the security component, because the POST'ed fields do not match the token supplied when the page was generated.
现在,我一直在使用 unlockedFields
可在此之前处理此操作:
Now, I have been using unlockedFields
to handle this before:
$this->Security->disabledFields = array(
'PrjRewardModifier.reward_id',
'PrjRewardModifier.title',
'PrjRewardModifier.option_type',
'PrjRewardOption.description',
'PrjRewardOption.modifier',
'PrjRewardOption.amount'
);
我知道 disabledFields
我们暂时使用它。
I know that disabledFields
is deprecated, but we are using that for the time being.
当我在 SecurityComponent
中调试已发布的表单数据时,我看到以下内容:
When I debug the posted form data in the SecurityComponent
, I see the following:
(int) 8 => 'PrjRewardModifier.0.reward_id',
(int) 9 => 'PrjRewardModifier.0.title',
(int) 10 => 'PrjRewardModifier.0.option_type',
(int) 11 => 'PrjRewardModifier.0.PrjRewardOption.0.description',
(int) 12 => 'PrjRewardModifier.0.PrjRewardOption.0.modifier',
(int) 13 => 'PrjRewardModifier.0.PrjRewardOption.0.amount'
我需要知道如何编辑数据传递到 unlockedFields
,以便它可以忽略hasMany关系的关键字段。
I need to know how to edit the data being passed to unlockedFields
so that it can disregard these fields that are keyed for hasMany relationships.
谢谢。 >
Thanks.
推荐答案
我有一个类似的问题。我发现在RewardModifier控制器中添加(等价于)这个函数:
I had a similar problem. I found adding (the equivalent of) this to the RewardModifier controller did the trick:
public function beforeFilter(){
$this->Security->unlockedFields = array('RewardOption');
}
这篇关于当它是hasMany关联的一部分时,如何“解锁”CakePHP表单中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!