在codeigniter中链接选择框引导程序

时间:2015-06-25 17:48:59

标签: php twitter-bootstrap codeigniter

我从bootstrap中选择框并从数据库填充数据到选择框。我使用的是codeigniter。但是我收到了错误消息'非法字符串偏移' enter image description here

这是我的观点

<?php foreach($option_provinsi as $data) { ?>
<option value=""><?=$data['nama_provinsi']?></option>
<?php } ?>

这是我的控制器

public function second_steps($page = 'payment_step_second') {
    $this->order_model->get_provinsi();
    $data['option_provinsi'] = $this->order_model->get_provinsi();

    $this->load->view('user/templates/header_payment', $data);

    $this->load->view('user/pages/' . $page, $data);
    $this->load->view('user/templates/footer_payment', $data);
}

这是我的模特

public function get_provinsi(){
    $result = array();
    $this->db->select('*');
    $this->db->from('provinsi');
    $this->db->order_by('nama_provinsi','ASC');
    $array_keys_values = $this->db->get();
    foreach ($array_keys_values->result() as $row)
    {
        $result[0]= '-Pilih Propinsi-';
        $result[$row->id_provinsi]= $row->nama_provinsi;
    }

    return $result;
}

之前谢谢

1 个答案:

答案 0 :(得分:0)

what you are doing looks a bit wrong - try the following your model: public function get_provinsi() { $obj = new stdClass(); $obj->nama_provinsi = "-Pilih Propinsi-"; $result = array( 0 => $obj ); $this->db->select('*'); $this->db->from('provinsi'); $this->db->order_by('nama_provinsi','ASC'); $query = $this->db->get(); foreach ($query->result() as $row) { $result[]= $row; } return $result; } your controller public function second_steps($page = 'payment_step_second') { $data = array('option_provinsi' => $this->order_model->get_provinsi()); $this->load->view('user/templates/header_payment', $data); $this->load->view('user/pages/' . $page, $data); $this->load->view('user/templates/footer_payment', $data); } and finally your view <?php foreach($option_provinsi as $data) { ?> <option value=""><?=$data->nama_provinsi; ?></option> <?php } ?>