我只是 php 和 codeigniter 的初学者,我试图将数据从模型传递到控制器,然后在视图中,但我有未初始化的变量,我将如何初始化它们?这是我的代码:
survaycontroller.php
<?php
class Survaycontroller extends CI_Controller{
// 'QID, Question, qA, qB, qC'
function index()
{
$this->load->view('survay_view');
$this->load->model('survay');
$survay_data = $this->survay->dosurvay($Question, $qA, $qB, $qC);
$viewData = array();
$viewData['survay_data'] = $survay_data;
$this->load->view(survay_view, $viewData);
}
}
?>
survay_view.php
</head>
<body>
<?php form_open('index'); ?>
<h1><?php echo $Question;?></h1>
<?php echo $qA; ?><?php form_checkbox('qA'); ?>
<?php echo $qB; ?><?php form_checkbox('qB');?>
<?php echo $qC; ?><?php form_checkbox('qC'); ?>
</body>
survay.php
<?php
class Survay extends CI_Model{
function dosurvay($Question, $qA, $qB, $qC){
$this->db->select('QID, Question, qA, qB, qC');
$this->db->from('tblquestions');
$this->db->where('Question', $Question);
$this->db->where('qA', $qA);
$this->db->where('qB', $qB);
$this->db->where('qC', $qC);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
}
?>