显示来自 MySQL Codeigniter 的图像



我的控制器是

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class pickoftheday_display extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('session');
        //$this->load->library('upload');
        //$this->load->library('form_validation');
        $this->load->helper('url');
        $this->load->model('pickoftheday_display_model','',TRUE);
        $this->pickoftheday_display_model->get_pickoftheday_image();
        $this->load->database();
    }
    public function index()
    {
                $this->load->view('pickoftheday_display');

    }
    public function get_pickoftheday_image()
    {
        $data['get_pick_picture']=$this->pickoftheday_display_model->get_pickoftheday_image();
    }
}

型号是

class pickoftheday_display_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->library('encrypt');
        $this->load->helper('security');
        $this->load->helper('string');
        $this->load->library('email');
    }
    public function get_pickoftheday_image()
    {
        $query=$this->db->query("SELECT * FROM pick_of_the_day order by id desc ");
        if($query->num_rows>0)
        {
            return $query->result();
        }
        else
        {
            return false;
        }
    }
}

视图代码为

    $val=array();
    $link=array();
    var_dump($get_pick_picture);
    foreach($get_pick_picture as $key)
    {
        $val[]= $key->image;
        $link[]= $key->link;
    }
echo $link[0]

如何在视图中显示图像..

  1. 您没有将数据传递到查看文件。
  2. 您没有设置要传递给查看文件的数据。

在索引函数中,你必须调用

public function index()
{
    $data['pick_picture']=$this->pickoftheday_model->get_pickoftheday_image();
    $this->load->view('pickoftheday_display',$data);
}

最新更新