如何在codeigniter中构建CRUD Slider?

oo7oh9g9  于 2023-05-27  发布在  其他
关注(0)|答案(3)|浏览(103)

你好,我想做滑块,但图像可以更改新图像,添加新图像或可以删除旧图像。
我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();
    }

请帮助我如何显示滑块图像从数据库?
谢谢。

xe55xuns

xe55xuns1#

我注意到你的代码中有一个错误,那就是图像路径。将该行更改为如下

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

可能是这个帮助。

crcmnpdw

crcmnpdw2#

动态滑块
stap 1:-在管理端创建简单上传图片的表单。LIKE(标题/描述/图片)
stap 2:-在控制器中启动选择查询,以在主滑块视图中显示图像和文本
stap 3:-将给定的slider.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>
ilmyapht

ilmyapht3#

试试这些它会工作

<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>

根据控件,您可以手动添加它们,因为我只是基本上向您展示如何通过图片进行迭代。

相关问题