如何在CodeIgniter中将值返回给模板?

时间:2017-09-25 02:38:36

标签: php codeigniter

对不起,我还在了解codeigniter的新内容。 我想问一下我在视图模型中有一个简单的查询,如下所示:

<h4 align="center"><?php echo '<b>'.strtoupper($data_mapel['nama_mapel']).'&nbsp; ('.$data_subjek_data['nama_subjek'].')</b>'; ?> </h4>

then, in controller model like this below :

public function view_soal($id_mapel,$id_paket){
    // needed data
    $data['data_subjek'] = $this->master->get_all_data('tb_subjek')->result();
    $id_subjek = $this->input->post('subjek');  
    $where = array('id_mapel'=>$id_mapel,'id_subjek'=>$id_subjek);
    $data['data_mapel'] = $this->master->find_data(array('id_mapel'=>$id_mapel),'tb_mapel')->row_array();
    $data['data_subjek_data'] = $this->master->find_data(array('id'=>$id_subjek),'tb_subjek')->row_array(); 
    //get data paket
    $where_paket = array('id'=>$id_paket);
    $data['data_paket'] = $this->master->find_data($where_paket,'tb_paket')->row_array();
    //get data view
    $data['data_view'] = $this->db->query("select a.*,b.nama_tema  from tb_pertanyaan a inner join tb_tema b on a.id_tema = b.id_tema where a.id_tema IN(select id_tema from detil_paket where id_paket ='$id_paket')")->result();
    $data['add_link'] = 'training';
    $data['view_file'] = $this->training.'view_soal';
    $this->load->view('template/media',$data);  
}

when i want to return value about data_subjek_data to view model and can be displayed, what should i do? 

1 个答案:

答案 0 :(得分:0)

$data_subjek_data的值$data['data_subjek_data']将存储在您的控制器中。

您可以在视图中使用

<?=$data_subjek_data->user_id ?>

OR

<?php
    foreach($data_subjek_data as $row){
        // loop with $row
    }
?>