使用图像CodeIgniter创建表

时间:2015-01-06 19:05:59

标签: php html codeigniter

该表仅显示文本,其中images列应显示实际图像,而不仅仅显示图像名称。

其他一切都很好而且效果很好但是如何显示图片?

控制器代码:

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

2 个答案:

答案 0 :(得分:0)

首先,您需要找到执行用户登录部分的部分。

如果未加载登录部分,则无法显示产品阵列的图像。

所以请确保

如果加载了登录部分,则无法找到产品数组(),因为在重定向之前(&#39;已记录&#39;)所以请更正它并为您工作

答案 1 :(得分:0)

控制器中的

我必须改变

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

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

这就解决了这个问题。