【发布时间】:2019-01-11 15:24:45
【问题描述】:
注意:这不是任何问题的重复,我需要回答这个具体问题。
下面是我的查看代码
<?php
$index = 1;
foreach ($questions as $ques): ?>
<tr>
<td><?php echo $index;?> </td>
<td> <?php echo $ques->question;?> </br>
<div class="custom-control custom-radio">
<input class="custom-control-input" type="radio" id="sdisagree[<?php echo $index;?>]" name="q<?php echo $ques->id;?>" value="1" >
<label class="custom-control-label" for="sdisagree[<?php echo $index;?>]"> Strongly Disagree
<input class="custom-control-input" type="radio" id="disagree[<?php echo $index;?>]" name="q<?php echo $ques->id;?>" value="2" >
<label class="custom-control-label" for="disagree[<?php echo $index;?>]">Disagree
<input class="custom-control-input" id="slightlydisagree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="3" >
<label class="custom-control-label" for="slightlydisagree[<?php echo $index;?>]">Slightly Disagree
<input class="custom-control-input" id="slightlyagree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="4" >
<label class="custom-control-label" for="slightlyagree[<?php echo $index;?>]">Slightly Agree
<input class="custom-control-input" id="agree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="5" >
<label class="custom-control-label" for="agree[<?php echo $index;?>]"> Agree
<input class="custom-control-input" id="sagree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="6" >
<label class="custom-control-label" for="sagree[<?php echo $index;?>]">Strongly Agree
</td>
</tr>
<?php
$index++;
endforeach ;?>
这是我的控制器,我想从视图中获得答案。
public function get_answer(){
//i don't know what to write here to get answers from the fields.
//am i required to use loops? if yes then how?
}
这是我的问题模型和控制器。
我从这个控制器中选择要问的问题。
public function survey_questions(){
$this->load->model("csv_model");
$data['survey'] = $this->csv_model->fetch_survey_questions();
$data["category"] = $this->csv_model->fetch_categories();
$this->load->view("survey_questions", $data);
}
我确实知道如何从视图中获取单个输入,例如
$variable = $this->input->post("fieldname");
然后将其传递给模型。但我对上面的代码感到困惑,如何从多个收音机中获取数据。
【问题讨论】:
-
您会得到所有发布的数据,如下所示:
$data = $this->input->post() -
是这样,但不知道从上面的观点如何?
标签: codeigniter model-view-controller input radio-button codeigniter-3