0
モデルを更新する必要がありますが、モデル自体のidの代わりにstudent_idを使用してモデルを探します。レコードを更新していますが、レコードID以外の値を取得していますID
私はこの解決策を考え出しましたが、それを実行するより良い方法があるのだろうかと疑問に思っていましたか?あなたは(すなわち。それはURL、POSTデータまたはセッションではありません)それを知らない場合はかなりあなたが更新されたレコードのIDを知っている必要があり、かつ
if (!empty($this->data)) {
// function that calculates score from answers in $this->data
$score = $this->OnlineExam->checkAnswers(2,$this->data);
// find the record
$record = $this->OnlineExam->find('first', array(
'conditions' => array('OnlineExam.student_id' => $this->Session->read('OnlineExam.studentId')),
'fields' => array('OnlineExam.id')));
// set the id and the score in the data array
$this->data['OnlineExam']['id'] = $record['OnlineExam']['id'];
$this->data['OnlineExam']['scoreB'] = $score;
// save the model
if($this->OnlineExam->save($this->data)) {
$this->redirect(array('controller' => 'OnlineExams', 'action' => 'page3'));
}
感謝.. – AlexBrand