【发布时间】:2016-02-25 05:53:54
【问题描述】:
我使用的是 Yii Framework 1.1.17,已经生成了三个模型: 问题、答案选项和响应。
关系:
Table: Question (list of questions)
id
text
Table: AnswerOption (list of possible answers, associated with question)
id
question_id
text
Table: Response (question and selected answer collector)
id
question_id
answer_option_id
text
我正在尝试创建一个表单,并诚然收集所有可能问题的答案。
文件:响应控制器
public function actionCreate()
{
// load all questions and with it the possible answer Options
$questions = Question::model()->findAll();
// get number of questions
$count = Question::Model()->count();
$model = array();
$i = 1;
while ($i <= $count) {
$model[] = Response::model();
$i++;
}
if (isset($_POST['Response'])) {
//
}
$this->render('create', array(
'model' => $model,
'questions' => $questions,
));
}
这是我遇到问题的领域:
文件:response/_form
<?php foreach($questions as $i=>$question): ?>
<?php echo CHtml::activehiddenField($question,"[$i]id"); ?> <?php echo $question['text']; ?>
<?php $options = CHtml::listData($question->answerOptions, 'id', 'text');?>
<?php echo CHtml::activeDropDownList(AnswerOption::model(), "[$i]text", $options, array('empty' => 'Select answer...')); ?>
<?php endforeach; ?>
我可能已经填写了我的问题和可能的答案,但我需要验证结果并将结果保存在 $model 中。
似乎我找不到有效解决此问题的方法。有人可以指导我吗?
【问题讨论】:
标签: php model-view-controller yii tabular