gpt4 book ai didi

CakePHP - $this->数据在 Model::save 之前消失

转载 作者:行者123 更新时间:2023-12-02 10:37:50 24 4
gpt4 key购买 nike

我的应用程序中有一个用于编辑 field 模型记录的页面。此页面在某个阶段可以正常工作,但现在已损坏。

在 Controller 操作中,调试 $this->data 给出了预期的表单值数组。但是,在 Venue 模型中,在 beforeSave 中调试 $this->data 仅给出相关 (HABTM) 模型中字段的值,类别:

app/models/venue.php (line 89)
Array
(
[Category] => Array
(
[Category] => Array
(
[0] => 1
[1] => 2
[2] => 8
)

)

)

在提交给 Controller 操作的表单和调用 beforeSave 之间,这些数据可能会发生什么情况?我应该在哪里调试这个?

谢谢

编辑 - 这是 Controller 中 $this->data 中的内容(实际数据已更改以删除电话号码、地址等)。

app/controllers/venues_controller.php (line 63)
Array
(
[Venue] => Array
(
[id] => 19
[city_id] => 1
[user_id] => 130
[name] => Acme Zoo
[email] => events@acmezoo.org.uk
[description] =>
Some text...

[blurb] => Truncated description...
[contact_id] =>
[address_1] => Acme Zoo
[address_2] => Some Road
[postcode] => PP9 4DD
[telephone] => 010101010101
[website] =>
[latitude] => 55.21222
[longtitude] => -2.111111
[featured] => 0
[active] => 1
[flagged] => 0
[smg] => 0
[smg_custom_icon] => 1
[listings] => 1
[send_email] => 0
[file] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

)

[Category] => Array
(
[Category] => Array
(
[0] => 3
[1] => 6
[2] => 10
)

)

)

这是我保存数据的代码...

    if (!empty($this->data)) {
if ($this->Venue->save($this->data)) {
$this->Session->setFlash('The venue has been saved','success');
$countryId = $this->Venue->City->field('country_id',array('id'=>$this->data['Venue']['city_id']));
if (!empty($this->data['Venue']['send_email'])){
$this->_emailVenue($this->Venue->id,'venue_added',$countryId);
}
$this->redirect(array('action' => 'index','city'=>$this->data['Venue']['city_id']));
} else {
$this->Session->setFlash('The venue could not be saved. Please, try again.','failure');
}
}

最佳答案

我想我找到了一个解决方案,但我真的不确定这是否应该被认为是一个“好的”解决方案。我在保存之前备份了请求数据,如果失败则恢复。

$temp = $this->request->data;

if ($this->Post->save($this->request->data)) {

}else{
$this->request->data = $temp;
}

关于CakePHP - $this->数据在 Model::save 之前消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7317329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com