我的模型之间有以下关系:
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'));
}
}
创建.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');
?>