How can I show images from assets in list view on a module?

edited September 2012 in News & Announcements
In my logos model, I insert an image name into the database.

How can I saw each image in the module list view?

I guess I should do something in the list_items function but I don't know what.

Thank you.

Comments

  • edited 6:02AM
    That's correct in that you will need to alter your list items function. You could try something like the following:
    function list_items($limit = NULL, $offset = NULL, $col = 'nav_key', $order = 'desc') { $data = parent::list_items($limit, $offset, $col, $order); foreach($data as $key => $value) { $data[$key]['image'] = '<img src="'.img_path($value['image']).'" alt="" />'; } return $data; }
  • edited September 2012
    my Products_model's ist_items method:

    function list_items($limit = NULL, $offset = NULL, $col = 'last_updated', $order = 'desc')
    {
    $this->filters = array('name_cn', 'ref');
    $this->db->select('id, name_cn, ref, price, photo, new, published, date_added, last_updated', FALSE);
    $data = parent::list_items($limit, $offset, $col, $order);
    foreach($data as $key => $val)
    {
    //translate mysql enum data to local language
    $data[$key]['new'] = lang($data[$key]['new']);

    //display product photo in list view
    // if have thumb image then show it, otherwise show defaut image
    $display_photo = !empty($data[$key]['photo']) ? img_path('product/' . $this->thumb_name($data[$key]['photo'])) : img_path('product/default_thumb.jpg');

    //show thumb image with HTML code
    $data[$key]['photo'] = '<<<<<img src="'.$display_photo.'" width="30px" />>>>';
    }

    return $data;
    }

    I prefer
    // PHP's original file exist check function
    file_exists(img_path('product/' . $this->thumb_name($data[$key]['photo'])))

    to
    //just check image name field in the database, not the image file
    !empty($data[$key]['photo'])


    yes, I'm lazyyyyyyyy
  • edited 6:02AM
    Don't think that's particularly lazy...

    Personally I'd check the database value first before taking the hit to check the disk. My 2 cents.
  • edited 6:02AM
    Thank you everyone, you helped a lot. And yes, I agree 66beta, lazy - you're not :)
  • edited 6:02AM
    Thank you everyone
Sign In or Register to comment.