使用codeigniter从模式引导程序的视图中获取一行

时间:2014-12-31 13:04:16

标签: jquery twitter-bootstrap codeigniter

我正在开发CI应用程序。我的问题是我想在一个模式中建立一个确认窗口,从视图中的表中查看一行中的数据。

我有这样的观点

PHP

<tbody>
 <?php
 $no = 1;
 foreach ($data_request as $data) {
 ?>

  <tr>
      <td class="sorting1"><?php echo $no++ . ". "; ?> </td>                                            
      <td class="sorting1"><?php echo $data['id_request']; ?> </td>
      <td class="center"><?php echo "$name"; ?></td>
      <td class="center"><?php echo date("d-m-Y, H:i ", strtotime($data['start_time'])); ?> </td>
      <td class="center"><?php echo $data['complaint']; ?></td>                                            
      <td class="center">
         <span class="label label-warning"><?php echo $data['status_request']; ?></span>
      </td> 

       <td class="center"><?php
           echo date("d-m-Y, H:i ", strtotime($data['closing_time']));
         ?> </td>                                            

      <td  class="right">
           <a class="btn btn-danger" href="#">
               <i class="halflings-icon white trash"></i> Close
           </a>

           <a class="btn btn-success btn-setting" href="#">
               <i class="halflings-icon pencil"></i> Print
            </a>
      /td>
  </tr>

         <?php } ?>
    </tbody>

HTML

  <div class="modal hide fade" id="myModal">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
            <h3>Your Request</h3>
        </div>
        <div class="modal-body">
            <p>This is preview :</p>

        </div>
        <div class="modal-footer">

            <a href="control_member" class="btn btn-primary">Print</a>
            <a href="#" class="btn" data-dismiss="modal">Back</a>
        </div>
    </div>

当用户点击按钮打印时,模态将显示选择的行,就像预览一样......?

我应该做什么,因为该表是使用SQL表中的数据构建的?

我想我有这样的解决方案:

IN MODEL:

SELECT * FROM tabel where id_request ...

或者我应该只编辑bootstrap模式的视图?

谢谢...

1 个答案:

答案 0 :(得分:0)

  1. 单击preview时,从表格中选择行的req_id(唯一ID)。

    <a class="btn btn-success btn-setting" href="#" id="print" req_id="<?php echo $data['id_request']; ?>"> <i class="halflings-icon pencil"></i> Print </a>

  2. 通过ajax将其传递给网址。

    $('#print').click(function() {
    
        var req_id = $(this).attr('req_id);
    
        var url = '<?php echo site_url("my_controller/get_row/"); ?>'+'/'+req_id;
    
        $.ajax({
            type: 'get',
            url: url,
            success: function (msg) {
                $('.modal-body').html(msg);
            }
        });
    });
    
  3. msg将是数据中的html或视图,您需要通过my_controller/get_row($id)方法从数据库中查询来编写。

  4. 示例msg:在class my_controller&#39; s method get_row($id)

    class My_controller extends CI_Controller {
        public function get_row($id) {
            $row = ...; // get the row by querying from your database & further process
            echo "This is the msg : ".$row;
        }
    }
    

    您也可以$row$this->load->view('template_name', ['row' => $row]);传递给视图,而不是直接从方法中打印出来。