【发布时间】:2021-07-21 10:41:23
【问题描述】:
所以我想使用 codeigniter 从数据库加载图像。这是我的代码:
控制器:Pweb
public function display($id=FALSE)
{
if ($id==FALSE){
$data["home_post"] = $this->M_pweb->displays();
$this->load->view('header');
$this->load->view('upload', $data);
$this->load->view('footer');
}else{
$data["post"] = $this->M_pweb->displays($id);
$this->load->view('header');
$this->load->view('upload', $data);
$this->load->view('footer');
}
}
型号:M_pweb
public function displays($id=FALSE)
{
if ($id==FALSE){
return $this->db->get("post")->result_array();
}else{
$query = $this->db->get_where("post", array('id'=>$id));
return $query->row();
}
}
观看次数:上传
<ul class="collection">
<?php foreach ($home_post as $data ): ?>
<li class="collection-item avatar">
<img src="<?=site_url("upload/post/".$data["filename"]) ?>" class="circle">
<p class="title"><?= $data["name"];?></p>
<small><?= $data["description"];?></small>
<a href="<?= site_url("pweb/upload/".$data["id"]) ?>" class="secondary-content">
<i class="material-icons">visibility</i>
</a>
</li>
<?php endforeach ?>
</ul>
它给出这样的错误:
遇到 PHP 错误 严重性:通知
消息:未定义变量:home_post
文件名:views/upload.php
行号:47
回溯:
文件:C:\xampp\htdocs\pweb\application\views\upload.php 行:47
函数:_error_handler
文件:C:\xampp\htdocs\pweb\application\controllers\Pweb.php 行:117
功能:查看
和
遇到 PHP 错误 严重性:警告
消息:为 foreach() 提供的参数无效
文件名:views/upload.php
行号:47
回溯:
文件:C:\xampp\htdocs\pweb\application\views\upload.php 行:47
函数:_error_handler
文件:C:\xampp\htdocs\pweb\application\controllers\Pweb.php 行:117
功能:查看
【问题讨论】:
标签: php codeigniter