使用图像 CodeIgniter 创建 table
Creation of table with images CodeIgniter
table 仅显示文本,其中图像列应显示实际图像,而不仅仅是图像名称。
其他一切都很好并且工作完美但是如何显示图片?
控制器代码:
function getData()
{
//check if the user is already logged in
if($this->session->userdata('logged_in'))
{
//the user is already logged in -> display the secret content
redirect('logged');
//get the session data
$session_data = $this->session->userdata('logged_in');
//get the username from the session and put it in $data
$data['user'] = $session_data['username'];
$config['base_url'] = site_url('LittleController/getData/');
$config['total_rows'] = $this->littlemodel->record_count('products');
$config['per_page'] = 10;
$this->pagination->initialize($config);
$data['Products'] = $this->littlemodel->getData(10, $this->uri->segment(3));
foreach ($data['Products'] as &$row)
{
$img = $row['image'];
$row['image']= "<img src='resources/images/thumbs/.$img'>";
//img('resources/images/thumbs/'.$img);
}
//$data["links"] = $this->pagination->create_links();
$this->load->view('mainpage1', $data);
}
else
{
//user isn't logged in -> display login form
$data['user'] = "Guest";
$config['base_url'] = site_url('LittleController/getData/');
$config['total_rows'] = $this->littlemodel->record_count('products');
$config['per_page'] = 10;
$this->pagination->initialize($config);
$data['Products'] = $this->littlemodel->getData(10, $this->uri->segment(3));
$data["links"] = $this->pagination->create_links();
$this->load->view('mainpage1', $data);
}
}
型号代码:
public function getData($limit, $offset)
{
$this->db->limit($limit, $offset);
$this->db->select('productName');
$this->db->select('productLine');
$this->db->select('productScale');
$this->db->select('productDescription');
$this->db->select('buyPrice');
$this->db->select('image');
$resultset = $this->db->get('products');
return $resultset->result_array();
}
查看代码:
$tmpl = array ( 'table_open' => '<table z-index="1000" id="table">' );
$this->table->set_caption("List of Products");
$this->table->set_heading('Name','Product Line','Product Scale','Product Description','Price per unit(€)','Image');
$this->table->set_template($tmpl);
echo $this->table->generate($Products);
首先,您需要找到执行用户登录部分的部分。
如果未加载登录部分,则没有显示产品数组图像的选项。
所以请确保
如果加载登录部分,它找不到产品数组(),因为在它重定向之前('logged'),所以请更正它并为你工作
在控制器中我必须更改
$row['image']= "<img src='resources/images/thumbs/.$img'>";
至
$row['image']= img(array('src'=>'resources/images/thumbs/'.$img.'', 'alt'=>'','width'=>'100px', 'height'=>'100px'));
这就是问题所在。
table 仅显示文本,其中图像列应显示实际图像,而不仅仅是图像名称。
其他一切都很好并且工作完美但是如何显示图片?
控制器代码:
function getData()
{
//check if the user is already logged in
if($this->session->userdata('logged_in'))
{
//the user is already logged in -> display the secret content
redirect('logged');
//get the session data
$session_data = $this->session->userdata('logged_in');
//get the username from the session and put it in $data
$data['user'] = $session_data['username'];
$config['base_url'] = site_url('LittleController/getData/');
$config['total_rows'] = $this->littlemodel->record_count('products');
$config['per_page'] = 10;
$this->pagination->initialize($config);
$data['Products'] = $this->littlemodel->getData(10, $this->uri->segment(3));
foreach ($data['Products'] as &$row)
{
$img = $row['image'];
$row['image']= "<img src='resources/images/thumbs/.$img'>";
//img('resources/images/thumbs/'.$img);
}
//$data["links"] = $this->pagination->create_links();
$this->load->view('mainpage1', $data);
}
else
{
//user isn't logged in -> display login form
$data['user'] = "Guest";
$config['base_url'] = site_url('LittleController/getData/');
$config['total_rows'] = $this->littlemodel->record_count('products');
$config['per_page'] = 10;
$this->pagination->initialize($config);
$data['Products'] = $this->littlemodel->getData(10, $this->uri->segment(3));
$data["links"] = $this->pagination->create_links();
$this->load->view('mainpage1', $data);
}
}
型号代码:
public function getData($limit, $offset)
{
$this->db->limit($limit, $offset);
$this->db->select('productName');
$this->db->select('productLine');
$this->db->select('productScale');
$this->db->select('productDescription');
$this->db->select('buyPrice');
$this->db->select('image');
$resultset = $this->db->get('products');
return $resultset->result_array();
}
查看代码:
$tmpl = array ( 'table_open' => '<table z-index="1000" id="table">' );
$this->table->set_caption("List of Products");
$this->table->set_heading('Name','Product Line','Product Scale','Product Description','Price per unit(€)','Image');
$this->table->set_template($tmpl);
echo $this->table->generate($Products);
首先,您需要找到执行用户登录部分的部分。
如果未加载登录部分,则没有显示产品数组图像的选项。
所以请确保
如果加载登录部分,它找不到产品数组(),因为在它重定向之前('logged'),所以请更正它并为你工作
在控制器中我必须更改
$row['image']= "<img src='resources/images/thumbs/.$img'>";
至
$row['image']= img(array('src'=>'resources/images/thumbs/'.$img.'', 'alt'=>'','width'=>'100px', 'height'=>'100px'));
这就是问题所在。