2016-02-18 50 views
-1

我有一个视图,显示来自数据库的数据,当点击时我的模态应该弹出,并会显示视图中显示的内容的更大图片,当我点击图像时没有任何反应任何想法如何我可以使这项工作?codeigniter模式不工作

控制器:

public function view_products() { 

      $id = $this->uri->segment(3); 
      $data['products'] = $this->user->viewprod($id); 
      $this->load->view('product_viewpage', $data); 

} 

我的模型:

public function viewprod($id) { 

$query = $this->db->query("SELECT * from product_table WHERE product_category = '$id'"); 
$r = $query->result(); 
return $r; 

} 

我的观点:

<html> 
    <head> 
     <meta charset="UTF-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 

     <title>Products</title> 

     <!-- Bootstrap --> 

     <link href='https://fonts.googleapis.com/css?family=Raleway:200' rel='stylesheet' type='text/css'> 

     <?php echo link_tag('css/Bootstrap.min.css')?> 
     <?php echo link_tag('css/bootstrap-theme.min.css')?> 
     <?php echo link_tag('css/STYLE01.css')?> 
     <?php echo link_tag('css/NAVIGATION.css')?> 
     <?php echo link_tag('assets/ICON.png')?> 
     <style type="text/css"> 
      ::-webkit-scrollbar-thumb:vertical { 
       background-color: #EF426F; /*color of main scrollbar*/ 
       height: 10px; /*height of scrollbar*/ 
      } 
      ::-webkit-scrollbar { 
       height: 0px; 
       width: 4px; /*width of the slider*/ 
       background-color: #FFFFFF; /*color of the slider*/ 
      } 
     </style> 
    </head> 

    <body> 
    <center> 

    <image src="<?php echo base_url() . 'assets/LOGO-(WHITE).png' ?> " width="890" height="220"> 
</center> 
<div class="container_products"> 
    <div class="row"> 
     <center><br><br><br> 

      <?php 
      foreach ($products as $alls) { 
       $id = $alls->product_id; 
$name = $alls->product_name; $description = $alls->product_description; 
$price = $alls->product_price; 
$picture = $alls->img_name. $alls->ext; 
       ?> 

     <div class="col-md-4"><a data-toggle="modal" data-target="#myModal"> 
         <img class = "bread_img" id = "bread_img_<?php echo $id;?>" src="<?php echo base_url() . 'assets/' . $picture; ?>" onMouseOut="this.src = '<?php echo base_url() . 'assets/' . $picture; ?>'" width="230" height="192"></a> 
         <input type ="hidden" id = "hidden_name_<?php echo $id;?>" value = "<?php echo $name;?>" > 
         <input type ="hidden" id = "hidden_desc_<?php echo $id;?>" value = "<?php echo $description;?>" > 
        <br><br> <h5 class="names" id="pname" src="<?php echo $name; ?>"><?php echo $name; ?></h5>₱&nbsp;<?php echo $price; ?> 
        <br><br><br><br><br> 
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
         <div class="modal-dialog modal-l"> 
          <div class="modal-content"> 
           <div class="modal-header"> 
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
            <h4 class="modal-title" id="myModalLabel"> <?php echo $name; ?></h4> 
           </div> 
           <div class="modal-body"> 
            <img src="<?php echo base_url() . 'assets/' . $picture; ?>" width="500" height="417" id = "modal_img"> 
            <br><br><h6 class="modal-title" id="myModalLabels"> <?php echo $description; ?></h6><br><br> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 

      <?php } ?> 



    </div> 
</div> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script> 

$(document.body).on('mouseover','.bread_img',function(){ 
    window.src_img = $(this).attr('src'); 
    id = $(this).attr('id').replace('bread_img_',''); 
    window.name = $('#hidden_name_'+id).val(); 
    window.text = $('#hidden_desc_'+id).val(); 


    $('#myModalLabel').text(name); 
    $('#myModalLabels').text(text); 
    $(this).attr('src','assets/VIEW.png'); 


}); 


$(document.body).on('click','.bread_img', '.names',function(){ 
    $('#modal_img').attr('src',src_img); 


}); 

</script> 
+0

向您的控制器显示载入模态的位置。 – user4419336

+0

我不认为它的负载模态问题,如果是的话,它会返回返回致命错误 – devpro

回答

-1

请试试这个代码 你忘了在你的控制器函数加载模式

public function view_products() { 



     $this->load->model('user'); 






     $id = $this->uri->segment(3); 
     $data['products'] = $this->user->viewprod($id); 
     $this->load->view('product_viewpage', $data); 

} 
+0

仍然无法工作,即使添加 – Christian