我的控制器是
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]
如何在视图中显示图像..
答案 0 :(得分:2)
在索引功能中,你必须调用
public function index()
{
$data['pick_picture']=$this->pickoftheday_model->get_pickoftheday_image();
$this->load->view('pickoftheday_display',$data);
}