0

'PatientCaseOrder'モデルとhasOneの関係を持つ'PatientCase'モデルがあります。(このテーブルには、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とpositionを含む配列を渡します。コードは500サーバーエラーを生成します、どこで間違っているのですか、それともこれに対して間違ったアプローチを取っていますか?

注:以前はPatientCaseモデルに位置フィールドがあり、このコード行は上記のコードセグメントで機能しました

$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 に答える