php使用codeigniter在表中显示图像

时间:2018-09-21 01:04:08

标签: php

大家好,我是第一次使用codeigniter进行编码,我创建CMS时上传图片并显示在滑块中,我的错误是backtrace,这是我的代码View.php

<section class="home-slider owl-carousel">
<?php foreach($data as $row) { ?>
  <div class="slider-item" style="background-image: url(); width: auto; background-repeat:no-repeat; background-size: contain; background-position:center;">
    <div class="container">
      <div class="row slider-text align-items-center">
      </div>
    </div>
  </div>
<?php } ?>

model.php

<?php

Class HomeModel扩展了CI_Model {

function __construct() {
    parent::__construct();
}

public function selectAllData() {
    $this->db->select("file_name,description"); 
    $this->db->from('tbl_slider');
    $query = $this->db->get();
    return $query->result();
} }

controller.php

class Home扩展了CI_Controller {

function __construct() {
    parent::__construct();
}

function index(){
    $this->load->model('HomeModel');
    $data['all_data'] = $this->HomeModel->selectAllData();
    $this->templates('home_index', $data);
}

function templates($page) {
    $this->load->view('templates/header');
    $this->load->view($page);
    $this->load->view('templates/navbar');
    $this->load->view('templates/footer');
    $this->load->view('templates/footer-js');
}
}

感谢您的回复

1 个答案:

答案 0 :(得分:0)

您需要如下设置背景图片的高度和网址:

<section class="home-slider owl-carousel">
    <?php foreach ($data as $row) { ?>
        <div class="slider-item" style="background-image: url(demo.jpg); height: 200px; width: auto; background-repeat:no-repeat; background-size: contain; background-position:center;">
            <div class="container">
                <div class="row slider-text align-items-center">
                </div>
            </div>
        </div>
    <?php } ?>
</section>