如何在codeigniter中构建CRUD滑块?

时间:2014-10-09 23:10:36

标签: php jquery codeigniter

你好我想制作滑块但是图像可以改变新图像,添加新图像或者可以删除旧图像。

我alredy让管理员管理滑块(添加,编辑,删除)但是当我想在视图中显示滑块时,它不起作用。

这是视图代码

<section id="main-slider" class="no-margin">
    <div class="carousel slide wet-asphalt">
        <ol class="carousel-indicators">
            <li data-target="#main-slider" data-slide-to="0" class="active"></li>
            <li data-target="#main-slider" data-slide-to="1"></li>
            <li data-target="#main-slider" data-slide-to="2"></li>
        </ol>
        <div class="carousel-inner">
            <?php if (count($galery)): foreach ($galery as $dt): ?>  
            <div class="item " style="background-image: <?php echo base_url('images/'.$dt->image); ?>">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="carousel-content centered">
                                <h2 class="animation animated-item-1"><?php echo $dt->nama; ?></h2>
                                <p class="animation animated-item-2"><?php echo $dt->content; ?></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!--/.item-->
            <?php endforeach; endif; ?>

        </div><!--/.carousel-inner-->
    </div><!--/.carousel-->
    <a class="prev hidden-xs" href="#main-slider" data-slide="prev">
        <i class="icon-angle-left"></i>
    </a>
    <a class="next hidden-xs" href="#main-slider" data-slide="next">
        <i class="icon-angle-right"></i>
    </a>
</section>

这是控制器

public function index()
{
    $this->data['galery']= $this->mgalery->get_galery();

    $this->data['contents'] = $this->load->view('user/galery', $this->data, true);
    $this->load->view('wrapper_user',$this->data);
}

这是模型

function get_galery()
    {
        $this->db->order_by('id_image','desc');
        $data = $this->db->get($this->tbl_galery);
        return $data->result();
    }

请帮我看看如何从数据库中显示滑块图片?

谢谢。

3 个答案:

答案 0 :(得分:0)

我注意到你的代码中有一件事是错误的,那就是图像路径。将此行更改为

 <div class="item " style="background-image: <?php echo base_url().'images/'.$dt->image; ?>">

可能是这个帮助。

答案 1 :(得分:0)

试试这些它会起作用

<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!--Indicators-->
<ol class="carousel-indicators">
    <?php for($i=0; $i < count($gallery); $i++){?>
    <?php if($i == 0){$active = 'active';}else{$active = '';}?>
    <li data-target="#myCarousel" data-slide-to="<?php echo $i;?>" class="<?php echo $active;?>"></li>
    <?php }?>
</ol>
<div class="carousel-inner">
     <?php foreach($gallery as $key => $row){?>
     <?php if($row['img_id'] == 1){$active = 'active';}else{$active = '';}?>
     <div class="item <?php echo $active;?>">
          <img src="<?php echo base_url().'images/'.$row['slider_image'];?>" />
          <div class="container">
              <div class="carousel-caption">
                 <h1><?php echo $row['slider_details'];?></h1>
              </div>
          </div>
      </div>
    </div>
</div>

根据控件,您可以手动添加它们,因为我只是基本上向您展示如何迭代图片。如果您有任何疑问,请随时发送电子邮件至sjk_lacoste@repoholding.com

答案 2 :(得分:0)

动态滑块

步骤1:-在管理员端创建简单上传图片的形式。喜欢(标题/说明/图片)

步骤2:-在控制器中触发选择查询,以将图像和文本显示到主滑块视图

步骤3:-将给定的lider.php文件代码粘贴到滑块空间并享受.....

  
<!-- Indicators -->
<ol class="carousel-indicators">

  <?php $temp = 0;

   if(count($img)){
    foreach ($img as $value) {

      if ($temp == 0) {

        echo '<li data-target="#myCarousel" data-slide-to="0" class="active"></li>';
        $temp++;
        }
        else{

              echo '<li data-target="#myCarousel" data-slide-to="'.$temp.'"></li>';

              $temp++;
            }

    }

  } ?>
</ol>

<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">

        <?php $temp = 0;

   if(count($img)){ 
    foreach ($img as $value) {

      if ($temp == 0) {  ?>

      <div class = "item active">
      <img src="<?php echo base_url('uploads/slider/')?><?php echo $value["IMAGE"] ?>" alt= "Image of every carousel" style="width:100%;height: 100%;>

        <div class ="carousel-caption">
        <div class ="carousel-caption">
      <h3><?php echo $value["TITLE"] ?></h3> 
      <p><?php echo $value["DESCRIPTION"] ?></p>
      </div>
  </div>

        <?php $temp++;
        }
        else{
         ?>


      <div class = "item">
      <img src="<?php echo base_url('uploads/slider/')?><?php echo $value["IMAGE"] ?>" alt="Image of every carousel" style="width:100%;height: 100%;>
      <div class="carousel-caption">
        <div class ="carousel-caption">
      <h3><?php echo $value["TITLE"] ?></h3> 
      <p><?php echo $value["DESCRIPTION"] ?></p></div> </div>

    <?php
        $temp++;
            }

    }

  } ?>

</div>


<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
  <span class="glyphicon glyphicon-chevron-left"></span>
  <span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
  <span class="glyphicon glyphicon-chevron-right"></span>
  <span class="sr-only">Next</span>
</a>