简体   繁体   English

来自控制器的Codeigniter呼叫方式

[英]Codeigniter Call Modal from Controller

I have a problem with calling a modal popup from controller... in this case i use datatables, and i want to make edit form as a modal popup... someone can help me...?? 我在从控制器调用模式弹出窗口时遇到问题...在这种情况下,我使用数据表,并且我想将编辑表单作为模式弹出窗口...有人可以帮助我...?

my datatables screenshot 我的数据表截图

here's my controller : 这是我的控制器:

function datatables(){
    $this->load->library('Datatables');
    $this->datatables->from('tb_rekap_wo_tj');
    $this->datatables->select('tj_id, tj_tanggal, tj_waktu_mulai, tj_waktu_selesai, tj_halte, tj_koridor, tj_teknisi1, tj_teknisi2, tj_petugas_halte, tj_permasalahan, tj_penanganan, tj_status, tj_keterangan');
    $this->datatables->add_column('edit', '<a href="wo_gt/edit/$1" title="Edit" onclick="wo_gt/edit/$1"><button class="btn btn-warning btn-sm"><i class="fa fa-pencil"></i></button></a> <a href="wo_gt/delete/$1"><button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></button></a>', 'tj_id');
    echo $this->datatables->generate();
}
public function edit($id) {
    $this->load->model('wo_model');
    $data = $this->wo_model->get_by_id($id);
    echo json_encode($data);
}

here's the result : 结果如下:

view result 查看结果

so my question is... how to show the result as a modal popup...?? 所以我的问题是...如何将结果显示为模式弹出窗口... ?? Thanks... 谢谢...

You can start with a HTML form 您可以从HTML表单开始

<div id="overlay" class="modal_overlay"></div>
<div id="dialog" class="modal_window">
"here comes the table or whatever you wish to input and alter data you get from your tables."
</div>

You'll also probably need an "Edit" button like this one: 您可能还需要这样的“编辑”按钮:

  <input type="button" id="btnShowModal" value="Modal Dialog" />

then add some CSS to it: 然后添加一些CSS:

<style type="text/css">


.modal_overlay
{
   position: fixed;
   top: 0;
   right: 0;
   bottom: 0;
   left: 0;
   height: 100%;
   width: 100%;
   margin: 0;
   padding: 0;
   background: #000000;
   opacity: .15;
   filter: alpha(opacity=15);
   -moz-opacity: .15;
   z-index: 101;
   display: none;
}
.modal_window
{
   display: none;
   position: fixed;
   width: 380px;
   height: 200px;
   top: 50%;
   left: 50%;
   margin-left: -190px;
   margin-top: -100px;
   background-color: #ffffff;
   border: 2px solid #336699;
   padding: 0px;
   z-index: 102;
   font-family: Verdana;
   font-size: 10pt;
}

and JS to fire the event. 和JS触发事件。

<script type="text/javascript">

   $(document).ready(function ()
   {

      $("#btnShowModal").click(function (e)
      {
         ShowDialog();
         e.preventDefault();
      });

      $("#btnClose").click(function (e)
      {
         HideDialog();
         e.preventDefault();
      });

      $("#btnSubmit").click(function (e)
      {
         //submit logic
         HideDialog();
         e.preventDefault();
      });

   });

   function ShowDialog()
   {
      $("#overlay").show();
      $("#dialog").fadeIn(300);
      $("#overlay").unbind("click");        
   }

   function HideDialog()
   {
      $("#overlay").hide();
      $("#dialog").fadeOut(300);
   } 

</script>

Basically you have an overlay which make the stuff appear modal, once you unbind the "click" it also feels that way. 基本上,您有一个覆盖层,使东西看起来像模态,一旦取消绑定“点击”,它也会有这种感觉。 I didn't tried this particular code out right now but I used this technique couple of times to make a modal window. 我现在还没有尝试过这个特定的代码,但是我几次使用这种技术制作了一个模态窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM