⚠ 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

Displaying an image in the Grid



xcoder
  • profile picture
  • Member

Posted 10 June 2012 - 17:10 PM

I have a table field that stores names of images located in a folder.
How can I display the images in the GC Grid?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 10 June 2012 - 17:21 PM

For now you cannot that's why I have created Image CRUD. For now it is still not finished but you can see a beta release at: http://www.web-and-development.com/image-crud-an-automatic-multiple-image-uploader-for-codeigniter/

fdias
  • profile picture
  • Member

Posted 10 June 2012 - 22:00 PM

web-johnny,

Couldn't a workaround be to use the [b]add_action [/b]function and pass the image as the URL? You could hide the column with the image file name but still get its value and use it as URL of the add_action image. You could even set the action of that button with the thumbnail to open the fullsize image on a new window or pop up.

I hope I was clear enough, if not let me know and I'll try to explain a littel further.

Check the documentation for add_action

http://www.grocerycrud.com/documentation/options_functions/add_action

Cheers.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 10 June 2012 - 22:16 PM

Yeap I understand what do you mean. And yes it is a good solution. The only thing that it is annoying to go to an image one by one. That's why I created image CRUD to have all the functionality in one page. For me grocery CRUD covers all of my needs for CRUD except if I want a photo gallery and that's why I created this library .Well I thing that [member='xcoder'] has his answer and he has to choose now ;)

xcoder
  • profile picture
  • Member

Posted 11 June 2012 - 07:01 AM

Thanks johnny...the Image Crud is a great library though I aint getting it working...The Crud is not displayng or uploading(failed) any images....

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 11 June 2012 - 21:44 PM

Did you try the online examples with the examples_database? What is not working exactly? Please ensure that your folder is writable first with 777 permission. Can you have a print-screen to help you?

xcoder
  • profile picture
  • Member

Posted 12 June 2012 - 11:13 AM

[img]http://gramdata.files.wordpress.com/2012/06/new-picture-1.png?w=300&h=175[/img]
Not displaying thumbnails nor uploading to the folder:

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 12 June 2012 - 23:31 PM

That's weird I will check it when I will find some time to debug it and I will tell you. Sorry it is just that I don't have developed it for a long time and I can't imagine what is wrong with this.

DeepVoid
  • profile picture
  • Member

Posted 03 July 2012 - 11:07 AM

[quote]I have a table field that stores names of images located in a folder.
How can I display the images in the GC Grid?[/quote]

I've just solved this issue using callback_column:


// this is the column (named "fileUser" in the database) where the thumbnail must appear
$crud->callback_column('fileUser',array($this,'showImage'));


As you can see, within the callback_column statement there is a call to a function, showImage(); the function is defined this way:


// this is the string replaced within the cell - this example refers to a localhost location, change it according to your needs
function showImage($value) {
return "<img src='http://localhost/CI_Project/assets/uploads/files/" . $value . "' width=100>";
}


Then I render the GC output, and pass everything to the view as usual:


$output = $crud->render();
$this->_example_output($output);


Perhaps this is a naive solution, but for basic needs it works very well.

Tindi_
  • profile picture
  • Member

Posted 03 April 2013 - 18:45 PM

This is a very nice solution and I've added to my project...I have a question how do I save an image path to the database? for example "assets/uploads/files/cat.png" is save in the images table so I can reference it like you have illustrated above?

 

Thanks.


davidoster
  • profile picture
  • Member

Posted 05 April 2013 - 16:13 PM

the path is predefined, so you just hardcode it before the filename.


Pakman
  • profile picture
  • Member

Posted 25 August 2013 - 12:23 PM

I've just solved this issue using callback_column:
 

// this is the column (named "fileUser" in the database) where the thumbnail must appear
$crud->callback_column('fileUser',array($this,'showImage'));
As you can see, within the callback_column statement there is a call to a function, showImage(); the function is defined this way:

// this is the string replaced within the cell - this example refers to a localhost location, change it according to your needs
function showImage($value) {  
   return "<img src='http://localhost/CI_Project/assets/uploads/files/" . $value . "' width=100>";
}
Then I render the GC output, and pass everything to the view as usual:

$output = $crud->render();
$this->_example_output($output);
Perhaps this is a naive solution, but for basic needs it works very well.

 

 

And how can I do in edit mode? thanks!


Martin Lobato
  • profile picture
  • Member

Posted 25 November 2016 - 21:25 PM

I've just solved this issue using callback_column:
 

// this is the column (named "fileUser" in the database) where the thumbnail must appear
$crud->callback_column('fileUser',array($this,'showImage'));
As you can see, within the callback_column statement there is a call to a function, showImage(); the function is defined this way:

// this is the string replaced within the cell - this example refers to a localhost location, change it according to your needs
function showImage($value) {  
   return "<img src='http://localhost/CI_Project/assets/uploads/files/" . $value . "' width=100>";
}
Then I render the GC output, and pass everything to the view as usual:

$output = $crud->render();
$this->_example_output($output);
Perhaps this is a naive solution, but for basic needs it works very well.

 

 

 

You are really a genius !!!!


vpanchal650
  • profile picture
  • Member

Posted 01 November 2017 - 08:01 AM

Yeap I understand what do you mean. And yes it is a good solution. The only thing that it is annoying to go to an image one by one. That's why I created image CRUD to have all the functionality in one page. For me grocery CRUD covers all of my needs for CRUD except if I want a photo gallery and that's why I created this library .Well I thing that [member='xcoder'] has his answer and he has to choose now wink.png

great!!!


Tpojka
  • profile picture
  • Member

Posted 13 January 2018 - 21:31 PM

Hello to all,

 

I have like similar issue here.

I am storing image in DB and on list grid I am getting that image in <img> tag (which is what I want) and it goes well. On edit page I am also getting image itself with link to be deleted - so far so good.

 

But on read page I am getting just link for opening image in new tab.

 

I tried solution of callback_field and it didn't work in this case - on read page there is still just link and not an image itself.

 

I tried to test it with conditional of state and it worked on edit page, for example but not on read page. On read page I am still having just link and not an image.

 

I narrowed it to line of 329 of library but can't take good result.

// this code block works

if ('edit' == $crud->getState()) {
    $crud->callback_field('logo', function($value, $primaryKey) {
        $url = base_url('assets/uploads/files/'.$value);
        return "<img src='" . $url . "' width=100>";
    });
}

// this one does not

if ('read' == $crud->getState()) {
    $crud->callback_field('logo', function($value, $primaryKey) {
        $url = base_url('assets/uploads/files/'.$value);
        return "<img src='" . $url . "' width=100>";
    });
}

List:

TP6XgVm.png

 

Edit:

563E0Fc.png

 

Read:

NmGipP1.png

 

 

I also tried `callback_read_field()` but it raises error that says library doesn't have that method. I noticed something similar as array, but not as method.

Also, in docs for callback_read_field method is said it is available from 1.6.0 version although latest version is 1.5.8. It is confusing, isn't it?

 

Am I wrong in something here? How to get mutation of value on read page?


Goran,


darkstalker
  • profile picture
  • Member

Posted 14 January 2018 - 00:08 AM

Last version is 1.6.0. Check again on the download page

Tpojka
  • profile picture
  • Member

Posted 15 January 2018 - 10:35 AM

Last version is 1.6.0. Check again on the download page

 

Thank you. It worked with 1.6.0

 

I was able to use next code:

$crud->callback_read_field('logo', function($value, $primaryKey) {
    return '<img src="/assets/uploads/files/'. $value .'" width=100>';
});

It would be good to include 1.6.0. into github.