0

我的“PatientCase”模型与“PatientCaseOrder”模型具有 hasOne 关系。(该表仅存储了 patientCase id 以及一个整数位置)

我正在使用 ajax 函数在我的 PatientCase 控制器中使用以下函数更新“PatientCaseOrder”中的位置字段

public function update_position(){
        Configure::write('debug', 0);
        $this->autoRender = false;
        $this->loadModel('PatientCaseOrder');
        $list = $_POST['list'];
        $errs = false;
        if($list){
            foreach($list as $position){
                $id = $position[0];
                $pos = $position[1];
                $this->PatientCase->id = $id;

                if(! $this->PatientCase->PatientCaseOrder->saveField('position', $pos))
                     $errs = true;
            }
        }

        echo json_encode ($errs);
    }

我正在向它传递一个包含 PatientCaseId 和位置的数组。该代码产生 500 服务器错误,我哪里出错了,或者我采取了错误的方法?

注意:我之前在 PatientCase 模型中有 position 字段,这行代码与上面的代码段一起使用

$this->PatientCase->saveField('position', $pos)
4

1 回答 1

1

您需要更改控制器功能以获得更好的调试:

改成Configure::write('debug', 2);

添加$this->layout = 'ajax';

并改变:if(! $this->PatientCase->PatientCaseOrder->saveField('position', $pos)) $errs = true;

到:

pr($this->PatientCase->PatientCaseOrder->saveField('position', $pos)); die;

然后在你的ajax函数中记录回调

console.log(returned_data);

并检查错误。

于 2013-02-08T13:19:14.310 回答