php - 在滑块 Codeigniter 中显示图像
问题描述
嗨,我使用 codeigniter 来简单的列表脚本。我为每个列表 5 张图片上传了多张图片……但是我在列表详细信息页面中显示时遇到了问题……
我有两个表properties
,media
Inmedia
有 3 列id
property_id
(与properties.id
and相同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>
我不明白为什么它不显示滑块中的图像...
解决方案
如果在配置中,site_url()
可以index.php
在最后。这会破坏你的图片网址。
如果您需要访问您的资源,请始终使用 base_url()
.
改变:
site_url('files/listing/'.$m['photo']);
至:
base_url('files/listing/'.$m['photo']);
推荐阅读
- android - org.gradle.api.tasks.TaskExecutionException:任务执行失败.. 原因:org.gradle.api.internal.tasks.compile.CompilationFailedException:
- node.js - 以编程方式跨 Azure、VSTS 和 Graph 访问 Microsoft 标识
- sql - SQL Server:如何使这个查询更高效/更快?
- python - 在滚动窗口中计算不同的字符串,包括使用 pandas 的 NaN
- r - 从R中的字符串获取首字母
- java - 对象变量在 Android 中从一个线程到另一个线程不可见
- arduino - 我在 arduino 中找不到 hid.h 文件
- sql - 如何在oracle中获取特定月份的两个日期之间的日期列表
- android - ConstraintLayout 如何影响子重力?
- oracle - 如何避免警告“IMP-00041:警告:创建带有编译警告的对象”?