简体   繁体   English

用图像创建表CodeIgniter

[英]Creation of table with images CodeIgniter

The table displays only text, where images column should display actual image instead of just the name of image. 该表仅显示文本,其中“图像”列应显示实际图像,而不仅仅是图像名称。

Everything else is fine and works perfectly but how to display the pictures? 其他一切都很好并且可以正常工作,但是如何显示图片呢?

controller code: 控制器代码:

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);

        }
    }

model code: 型号代码:

        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();
    }

view code: 查看代码:

    $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);

First, you need to find which section is executed user login section. 首先,您需要找到执行用户登录部分的部分。

If login section is not loaded, there is no option to display the image the product array. 如果未加载登录部分,则没有选项来显示产品阵列的图像。

so please ensure it 所以请确保

If login section is loaded, it can not find the product array() because before it redirects ('logged') so please correct it and works for you 如果登录部分已加载,则找不到产品array(),因为在重定向(“已记录”)之前,请对其进行更正并为您工作

in the controller I have to change 在控制器中我必须改变

$row['image']= "<img src='resources/images/thumbs/.$img'>";

to

$row['image']= img(array('src'=>'resources/images/thumbs/'.$img.'', 'alt'=>'','width'=>'100px', 'height'=>'100px'));

that's sets the issue. 这就是问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM