问题描述:

Images are not showing on my view. When I do var_dump($image) it shows me valid result. When I load my view on browser images boxes appears but images not. I am using codeigniter.

网友答案:

try this.

CI is MVC(Model,View,Controller) format so always follow that as well.

controller

in your controller under main controller define

    public function  __construct()
{
    parent::__construct();
    $this->load->model('Product_area_model');

}

this should be your controller

    public function function_name()//define your funtion name
{
    $data['images'] = $this->Product_area_model->get_image();
    $data['data'] = $this->Product_area_model->product_list();
    $data['main_content'] ='admin/product_area/product_list';//don't know what you going to get. just insert cz of your purpose

    $this->load->view('includes/template',$data);
}

In Model

   public function get_image()
{
   //code to retrieve image names 
    $dirname = "uploads/";
    $images = glob($dirname."*");
    return $images;
}

in View

<?php
foreach($images as $image)
{
    ?>
    <td><img src="<?php echo base_url(); ?><?php echo $image ?>" height="100" width="100"></td>
<?php
}
?>
相关阅读:
Top