首页 > 解决方案 > 在滑块 Codeigniter 中显示图像

问题描述

嗨,我使用 codeigniter 来简单的列表脚本。我为每个列表 5 张图片上传了多张图片……但是我在列表详细信息页面中显示时遇到了问题……

我有两个表propertiesmediaInmedia有 3 列id property_id(与properties.idand相同photo(这是图像名称 + 扩展名)

控制器:Properties.php

 <?php
 defined('BASEPATH') OR exit('No direct script access allowed');

class Properties extends My_Controller {

public function __construct(){
    parent::__construct();
    $this->load->model('Property');
}
public function details($slug){
    $this->data['listing'] = $this->Property->find_by_slug($slug);
    $this->load_theme('properties/details');
}

}

型号:Property.php

  <?php
   defined('BASEPATH') OR exit('No direct script access allowed');

    class Property extends CI_Model{

var $table = 'properties';

function find_by_slug($slug){
    $this->db->select('properties.*,users.*,media.photo');
    $this->db->join('users', 'users.id = properties.user_id');
    $this->db->join('media', 'media.property_id = properties.id');
    $this->db->where('slug',$slug);
    return $this->db->get($this->table,1)->row_array();
}
}

查看:details.php

                            <div class="carousel-inner">

                                 <div class="item active">
                                        <?php $x = 0; ?>
                  <?php if($listing):?>
                <?php foreach ($listing as $m):?>
                <?php $x++ ; ?>
                                 <div class="item <?php if ($x == 1) echo 'active' ?>">
                                    <img src="<?php echo site_url('files/listing/'.$m['photo'])?>" class="thumb-preview" alt="<?php echo $m['alt'];?>">
                                    </div>

                 <?php endforeach;?>
              <?php endif;?>
              </div>

我不明白为什么它不显示滑块中的图像...

标签: phpcodeigniter-3

解决方案


如果在配置中,site_url()可以index.php在最后。这会破坏你的图片网址。

如果您需要访问您的资源,请始终使用 base_url().

改变:

site_url('files/listing/'.$m['photo']); 

至:

base_url('files/listing/'.$m['photo']);

推荐阅读