gpt4 book ai didi

php - 无法将数据从一个表保存到另一个表

转载 作者:行者123 更新时间:2023-11-29 12:40:42 25 4
gpt4 key购买 nike

在 cakephp 中,我无法将从 1 个表返回的数据保存在另一个表中。我已经从 Tutors 表中预先填充了数据,我想要做的就是将此数据保存为表 coachEdit 中的新行(不要与编辑功能混淆)。我遇到的问题是我获取了要保存的数据,但 coachEdit 没有保存任何返回的数据(没有错误)。

public function tutor_edit($id = null) {
$this->loadModel('Tutor');

$this->Tutor->id = $id;

debug($this->request->data );

if (!$this->Tutor->exists()) {
throw new NotFoundException(__('Invalid tutor'));
}
if ($this->request->is('post') ) {

if ($this->TutorEdit->save($this->request->data)) {
$this->Session->setFlash(__('The tutor details to be edited have ben forwarded to management'), 'flash_success');
// $this->redirect(array('controller'=> 'tutors' , 'action' => 'tutordetails'));
} else {
$this->Session->setFlash(__('The tutor edit details could not be saved. Please, try again.'), 'flash_alert');
}



} else {
$this->request->data = $this->Tutor->read(null, $id);
}

/////
<?php
echo $this->Form->create('Tutor',array('class' => 'form-horizontal'));
echo $this->Form->input('id', $formHorizontalHtmlOptions);
echo $this->Form->input('first_name', $formHorizontalHtmlOptions);
echo $this->Form->input('last_name', $formHorizontalHtmlOptions);
echo $this->Form->input('email', $formHorizontalHtmlOptions);
echo $this->Form->input('mobile', $formHorizontalHtmlOptions);
echo $this->Form->input('home_phone', $formHorizontalHtmlOptions);
echo $this->Form->input('work_phone', $formHorizontalHtmlOptions);
echo $this->Form->input('gender', array_merge($formHorizontalHtmlOptions, array('type' => 'select', 'options' => $gender)));
echo $this->Form->end('Save Edit Request');
?>

http://book.cakephp.org/2.0/en/models/saving-your-data.html 中没有看到任何有关此内容的信息

最佳答案

因为您尝试保存的数据是“Tutor”,而不是“TutorEdit”。在您共享的链接中,第一部分显示了需要保存的正确数组格式。

试试这个:

if ($this->request->is('post')  ) {
$tutoredit = array('TutorEdit' => $this->request->data['Tutor']);

if ($this->TutorEdit->save($tutoredit)) {
$this->Session->setFlash(__('The tutor details to be edited have ben forwarded to management'), 'flash_success');
} else {
$this->Session->setFlash(__('The tutor edit details could not be saved. Please, try again.'), 'flash_alert');
}
}

关于php - 无法将数据从一个表保存到另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26161251/

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