Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Codeigniter将id传递给引导模式?_Javascript_Php_Jquery_Twitter Bootstrap_Codeigniter - Fatal编程技术网

Javascript 如何使用Codeigniter将id传递给引导模式?

Javascript 如何使用Codeigniter将id传递给引导模式?,javascript,php,jquery,twitter-bootstrap,codeigniter,Javascript,Php,Jquery,Twitter Bootstrap,Codeigniter,我有一个产品列表,希望进行编辑 当我点击特定产品的编辑按钮时,打开一个引导模式,点击ID更新内容 数据清单: <?php if (is_array($product_list)) { foreach ($product_list as $item): ?> <tr> <td> <?=$item['product_name']?></td> <

我有一个产品列表,希望进行编辑

当我点击特定产品的编辑按钮时,打开一个引导模式,点击ID更新内容

数据清单:

 <?php if (is_array($product_list)) {
    foreach ($product_list as $item): ?>
        <tr>
          <td>
            <?=$item['product_name']?></td>
          <td>
            <a href="#" class="btn btn-small z-depth-0" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo" id="mts" data-id="<?=$item['product_id']?>" data-name="<?=$item['product_id']?>">
              <i class="mdi mdi-editor-mode-edit"></i>
            </a>
          </td>
        </tr>
        <?php endforeach;}


我试图解释如何做到这一点

你的控制器

class Products extends CI_Controller
{
    public function listing()
    {
        $arrViewData = array("product_list" => $this->your_model->getListData());
        $this->load->view("your-list-of-data-view", $arrViewData);
    }

    public function item($productId)
    {
        $arrViewData = array("product_item" => $this->your_model->getItem());
        $this->load->view("backend/pop", $arrViewData);
    }
}
您的列表视图

<?php if (is_array($product_list)) {
    foreach ($product_list as $item): ?>
        <tr>
          <td>
            <?=$item['product_name']?></td>
          <td>
            <a href="#" class="btn btn-small z-depth-0 product-item" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo" data-id="<?=$item['product_id']?>" data-name="<?=$item['product_id']?>">
              <i class="mdi mdi-editor-mode-edit"></i>
            </a>
          </td>
        </tr>
<?php endforeach;}

<!-- some where this code hast to be within your body -->
<div class="modal fade in" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" style="    background-color: #fff; border-radius: 2px;">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
    </div>
  </div>
</div>


我试图解释如何做到这一点

你的控制器

class Products extends CI_Controller
{
    public function listing()
    {
        $arrViewData = array("product_list" => $this->your_model->getListData());
        $this->load->view("your-list-of-data-view", $arrViewData);
    }

    public function item($productId)
    {
        $arrViewData = array("product_item" => $this->your_model->getItem());
        $this->load->view("backend/pop", $arrViewData);
    }
}
您的列表视图

<?php if (is_array($product_list)) {
    foreach ($product_list as $item): ?>
        <tr>
          <td>
            <?=$item['product_name']?></td>
          <td>
            <a href="#" class="btn btn-small z-depth-0 product-item" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo" data-id="<?=$item['product_id']?>" data-name="<?=$item['product_id']?>">
              <i class="mdi mdi-editor-mode-edit"></i>
            </a>
          </td>
        </tr>
<?php endforeach;}

<!-- some where this code hast to be within your body -->
<div class="modal fade in" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" style="    background-color: #fff; border-radius: 2px;">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
    </div>
  </div>
</div>


你的模态体看起来怎么样我不认为它会以你想要的方式工作-因为你需要ajax-我给你举一个例子如何在几分钟内完成这一点作为回答你不能将javascript值传递给php脚本那么,你面临什么问题?以及,你的问题是什么?@ManishTiwari检查这个我已经给出了一个答案根据你的需要应用它…你的模态体看起来怎么样我不认为它会以你想要的方式工作-因为你这里需要ajax-我给你一个例子如何在几分钟内完成作为一个答案你不能将javascript值传递给php那么,你面临的问题是什么?以及,你的问题是什么?@ManishTiwari检查这个我已经给出了一个答案根据你的需要应用它…这个方法做什么$.get你能解释它和我在哪里加载pop.php表单$.get是一个jquery函数更多的信息你能在这里得到,它做什么-点击你的编辑链接,它会打开一个模式,并通过ajax从你的数据库中获取数据控制器,它提供带有项目数据的pop视图,然后-如果ajax调用成功,数据将附加到您的模式内容中。该方法的作用$。get能否解释它以及我在何处加载pop.php表单$。get是一个jquery函数。单击您的编辑,您可以在此处获得更多信息以及它的作用链接它打开一个模式,并通过ajax数据从控制器中获取数据,该控制器提供带有项目数据的pop视图,之后,如果ajax调用成功,数据将附加到模式内容div中
<?php if (is_array($product_list)) {
    foreach ($product_list as $item): ?>
        <tr>
          <td>
            <?=$item['product_name']?></td>
          <td>
            <a href="#" class="btn btn-small z-depth-0 product-item" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo" data-id="<?=$item['product_id']?>" data-name="<?=$item['product_id']?>">
              <i class="mdi mdi-editor-mode-edit"></i>
            </a>
          </td>
        </tr>
<?php endforeach;}

<!-- some where this code hast to be within your body -->
<div class="modal fade in" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" style="    background-color: #fff; border-radius: 2px;">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
    </div>
  </div>
</div>
<script type="text/javascript">
   $(document).ready(function () {
      $(document).on("click", ".product-item", function () {
          var product_id = $(this).data('id');
          $('#exampleModal').on('show.bs.modal', function (event) 
          {
              // I am confused here
            $.get("/products/item/"+product_id+"/", function(data)   {
                $("div.modal div.modal-content").append(data);
            });

          });
      });
   });    
</script>