如何在 Codeigniter 中使用模态,具有单独的数据和特定的 id


How to use modal in Codeigniter, with separate data and certain id?

我有一个视图页面(ikhtisar_view)。当我单击一个 ID 时,它显示模态(链接到 ikhtisar/详细信息)仅包含该 ID 的数据。

这是我的 ikhtisar 视图 td(包含我可以单击以获取详细信息的数据):

<td><a href="<?php echo base_url();?>index.php/ikhtisar/detail" class='iframe'><?php echo $ikh['id']?></a></td>

这是我的控制器功能:

 public function detail()
 {
    $this->load->model('ikhtisar_model');
    $detailr = $this->ikhtisar_model->trx();
    $data['detail'] = $detailr;
    $this->load->view('ikhtisar/trx_view',$data);
 }

这是我的模型函数:

 public function trx()
 {  
    $ikh = $this->input->post('id');
    $this->db->select('t.id_transaksi AS id, t.tgl_transaksi AS tgl, t.id_member AS memberid, t.nama AS nama, p.kode_produk AS kode, tp.hp_tujuan AS nohp, d.nama AS nama2, t.saldo_awal AS saw, tp.hpp AS hpp, t.saldo_akhir AS sak, tp.laba AS laba, t.ket AS ket, sr.ket AS ket2, sr.jenis AS sj', FALSE)
->from('transaksi_pulsa tp')
->join('transaksi t','tp.id_transaksi=t.id_transaksi', 'left')
->join('produk p','tp.kode_produk = p.kode_produk', 'left')
->join('set_report sr','t.status=sr.jenis', 'left')
->join('distributor d','tp.id_distributor=d.id_distributor and tp.com=d.com', 'left')
->where('t.id_transaksi', $ikh);
$ikhtisar = $this->db->get();
    return $ikhtisar;       
 }  

最后这是我trx_view.php:

<table class="table table-striped table-hover table table-bordered" id="ikhtisar">
        <thead style="display: table-header-group; vertical-align: middle; border-color: inherit;">
        <tr>
            <th>Status</th> 
            <th>No</th>
            <th>Tanggal</th>
            <th>Kode RS</th>
            <th>Nama RS</th>
            <th>Produk</th>
            <th>Tujuan</th>
            <th>Stok</th>
            <th>Harga</th>
            <th>Saldo Akhir</th>
            <th>Laba</th>
        </tr>
        </thead>
        <tbody>
          <?php foreach($ikhlist->result_array() as $ikh): ?>
          <tr>
            <!--<td><a href="http://localhost/modal/modal.php" data-toggle="modal" data-target="#myModal"><?php echo $ikh['id']?></a></td>-->
            <td style="font-size: 15px;" align="center"><?php if($ikh['sj'] == '1'){?><span><i class="glyphicon glyphicon-ok green"></i></span><?php }elseif($ikh['sj'] == '2'){ ?><span><i class="glyphicon glyphicon-remove red"><?php }else{ ?><span><i class="glyphicon glyphicon-question-sign yellow"><?php }?></i></span></td>
            <td><?php echo $ikh['id']?></td>                                
            <td><?php echo $ikh['tgl']?></td>
            <td><?php echo $ikh['memberid']?></td>
            <td><?php echo $ikh['nama']?></td>
            <td><?php echo $ikh['kode']?></td>
            <td><?php echo $ikh['nohp']?></td>
            <td><?php echo $ikh['nama2']?></td>
            <td class="text-right"><?php echo number_format($ikh['hpp'], 0, ",", ".")?></td>
            <td class="text-right"><?php echo number_format($ikh['sak'], 0, ",", ".")?></td>
            <td><?php echo $ikh['laba']?></td>
          </tr>
          <?php endforeach; ?>
        </tbody>
    </table>

但我只有一个没有数据的页面(trx_view.php)。它只包含标题。那么,如何显示正确的数据呢?在ikhtisar_view(点击 id 了解详细信息之前),没问题。

尝试自己调试代码,尝试从模型中打印查询,方法是使用

echo $this->db->last->query()

尝试在上面收到的查询数据库上运行该查询,并检查是否正在获取数据。

然后尝试在视图中打印$detail变量,并检查视图是否实际获取数据。

如果我在ikhtisar_view中使用它:

<td>
<form  method="post" action="<?php echo base_url();?>index.php/ikhtisar/detail">
    <input type="hidden" name="id" 
    value="<?php echo $ikh['id']; ?>" />
    <input type="submit" value="<?php echo $ikh['id']; ?>" />
</form> 
</td>

而不是:

<td><a href="<?php echo base_url();?>index.php/ikhtisar/detail" class='iframe' name="id">
<input name="id" value="<?php echo $ikh['id']; ?>" />
</a></td>   

表单方法成功,我单击的数据恰好是 (id)。但是,这不是模式。如何将其转换为模态?我已经尝试将class='iframe'添加到该方法中,但它不起作用。模态显示,但空白,没有数据,没有页眉,没有页脚。