⚠ 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

how to use $crud->callback_upload();



bob jones
  • profile picture
  • Member

Posted 19 May 2012 - 02:30 AM

Hi everyone,

This is pretty basic I'm sure. I would like to redirect to another controller method when the upload button is pushed. I have come across $crud->callback_upload, and would like to use this to do it.

So far I havn't got it working. My code is $crud->callback_upload('main/example1'); main is the controller, with example1 being a method I want to call. How do Imake this work

Thanks in advance,

Bill

bob jones
  • profile picture
  • Member

Posted 21 May 2012 - 03:56 AM

Hello everyone,

I was hoping for a slightly stronger response to my question :) . Anyway Let me give a few more details about what I'm trying to do:

I have an upload field with an associated upload button. when the button is clicked I would like to override its functionality and substitute the image_crud library ( also developed by John Skoumbourdis --Thanks John ) so that I can upload multiple images instead of the 1 allowed by grocery_crud at present.

Here is my code:

............


$crud->set_field_upload('slideshow','assets/uploads/files');

$crud->callback_upload(array($this,'example1'));
$output = $crud->render();
$this->_example_output($output);


.......................


function example1()
{
$this->load->library('Image_CRUD');
$image_crud = new Image_CRUD();

$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_1')
->set_image_path('assets/uploads');

$output = $image_crud->render();

$this->_example_output($output);

return ;
}


.....................

Unfortunately this does not work and the functionality of the upload button is not replaced. Could anyone please explain what I'm doing wrong?

Thank you in advance,

Bill

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

Posted 23 May 2012 - 21:13 PM

Hello [member='bob jones'] and sorry for the delayed answer. As I see at your code you have it wrong. The example show the method callback_after_upload and not callback_upload.

So if you just change the :


$crud->callback_upload(array($this,'example1'));


to:


$crud->callback_after_upload(array($this,'example1'));


I think it will be fine.

Just let me know if this works for you

P.S. The callback_upload is not documented and the use is really rear for users more familiar with grocery CRUD, so it is better to use callback_before_upload and callback_after_upload as it has also documentation with examples.

Regards
Johnny

remi1
  • profile picture
  • Member

Posted 24 May 2012 - 14:40 PM

For example: i want to save an image as a longtext encoded string in my db. i think i would need to use the callback_upload. On checking the gc library. i saw the uploader class in use but i dont want to use that.

By the way, this is my first time on this forum and i have something to say
GROCERY CRUD ROCKS!!!

bob jones
  • profile picture
  • Member

Posted 24 May 2012 - 16:11 PM

Hi Johnny,

Thank you for looking at it.

I have tried:

$crud->callback_after_upload(array($this,'example_callback_after_upload'));

have also tried:

$crud->callback_before_upload(array($this,'example_callback_before_upload'));

The upload part seems to go fine and I have confirmed that the file has been uploaded to the correct folder.

In my project, I am using the ion_auth authorization system. I am accessing grocerycrud from within a 'protected' controller ( meaning that the user has to be logged to use this controller. )

I am basing all this on http://jondavidjohn.com/blog/2011/01/scalable-login-system-for-codeigniter-ion_auth, and using a system of extended controllers right out of the article

The advantage of this, is that I have access to an object $this->the_user within the protected controller which contains the current user data.

When I step through the code with xdebug I inspected the $this object in:

$crud->callback_after_upload(array($this,'example_callback_after_upload'));

This appears to be the extended $this object used with $this->the user. I think this is the problem. I've tried:

$crud->callback_before_upload(array($crud,'example_callback_before_upload'));

but this also causes an error.

Thank you,

Bill