无法在Codeigniter视图文件

时间:2016-04-23 10:14:10

标签: php mysql codeigniter

提前thnx我从db获取一些记录,然后通过其他一些数据发送该结果。但不确定如何在下拉列表中访问该结果值。

控制器

$xap = $this->captchaGen();
$data['states'] = $this->Register_model->ListStates();
$data1 = array(
    'captcha' => $xap['image'],
    'message' => '',
    'state' => $data
);
$this->load->view('login', $data1);

查看

foreach ($state as $row) {
    $options[$row->name] = $row->name;
}
$js = 'id="c_stat"  class="form-control"';
echo form_dropdown('c_stat', $options, set_value('c_stat'), $js);

2 个答案:

答案 0 :(得分:1)

在控制器中

将数据传递给视图

 $xap=$this->captchaGen();
    $data['states'] = $this->Register_model->ListStates();
    $data['captcha'] = $xap['image'];
    $data['message'] = "";
    $this->load->view('login', $data);

观看

foreach ($states as $row)
{

}

答案 1 :(得分:0)

**Try this** 

In controller 
$states = $this->Register_model->ListStates();
$data['captcha'] => $xap['image'];
$data['message'] => '';
$data['state'] => $states;

$this->load->view('login', $data);

And in view 
foreach ($state as  $value) {

}

传递$ data代替$ data1

$ this-> load-> view(' login',$ data1);

将其替换为

$ this-> load-> view(' login',$ data);