モデル間には次のような関係があります。
Assignment hasMany Question
Question belongsTo Assignment
Question hasMany Answer
Answer belongsTo Question
課題、質問、回答を保存できる単一のフォームが欲しいのですが。
フォームはほぼ機能しており、課題情報と質問は保存されますが、回答は保存されません。
割り当てコントローラー作成アクション:
function create() {
if (!empty($this->data)) {
var_dump($this->data);
unset($this->Assignment->Question->validate['assignment_id']);
unset($this->Assignment->Question->Answer->validate['question_id']);
$this->Assignment->saveAll($this->data, array('validate' => 'first'));
}
}
create.ctp
Create new assignment
<?php
echo $this->Form->create('assignment', array('action' => 'create'));
echo $this->Form->input('Assignment.title');
echo $this->Form->input('Assignment.type');
echo $this->Form->input('Question.0.question');
echo $this->Form->input('Question.0.Answer.0.answer');
echo $this->Form->end('Create');
?>