⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Callback column to show thumbnail from a different table



Qarlo
  • profile picture
  • Member

Posted 06 May 2012 - 13:10 PM

Hi,
I have these two tables in the database:

Subservices:
id, ..., background_id

Backgrounds:
id, filename

With grocery crud I'd like to show the background thumbnail (which is the "filename" field) in a column of subservices.

In the controller I have this:


function index()
{
$crud = new grocery_CRUD();
...
$crud->columns('service_id', 'name','english_name', 'italian_text', 'english_text',
'background_id');
...
$crud->set_relation('background_id', 'backgrounds', 'filename');
$crud->callback_column('background_id', array($this, 'show_picture_in_row'));
...
}
function show_picture_in_row($id, $row)
{
$string = '<img src="images/backgrounds/thumbs/'.$row->filename.'" />';
return $string;
}


It's not working. It just displays the filename, for example: picture_1.jpg

What am I doing wrong?

casachit
  • profile picture
  • Member

Posted 09 May 2012 - 15:07 PM

This is how i solved the problem. I hope it may help you

function show_picture_in_row($value, $row)
{
$path=base_url();
$this -> db -> where('cat_id', $row->cat_id);
$select = $this -> db -> get('category') -> row();
$string = "<img src='$path"."uploads/albumarts/table/$select->album_art'/>";
return $string;
}