⚠ 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 handle delete button?



christian1988
  • profile picture
  • Member

Posted 12 February 2012 - 10:29 AM

hi,
i have a table with 2 fields, the first is the id that references another table and is not unique, while the second is the name of an image.
my primary is both of them.

primary key ( id, images)

i need to add and delete entry so i tried this code:


//Carico la libreria CRUD
$this->load->library('grocery_CRUD');
$crud = new grocery_CRUD();


$crud->set_table('immagini');
$crud->required_fields('immagine');
$crud->set_relation('id','cani','nome');
$crud->set_field_upload('immagine','assets/uploads/files');
$output = $crud->render();


but when i try to delete one row the system delete all the entry with the same id...i need to handle this operation because that's not rigth for me, i need that only the selected row is deleted...can i handle the delete button?

i've already try with getState:


state = $crud->getState();
$state_info = $crud->getStateInfo();

if($state == 'delete')
{
$primary_key = $state_info->primary_key;
//Do your awesome coding here.
echo "handle";
}


but it doesn't work...

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

Posted 12 February 2012 - 12:52 PM

Yes you can handle the delete with a callback_escape_delete . You can see an example at: http://www.grocerycrud.com/crud/function_name/callback_escape_delete

christian1988
  • profile picture
  • Member

Posted 12 February 2012 - 14:56 PM

[quote name='web-johnny' timestamp='1329051127' post='498']
Yes you can handle the delete with a callback_escape_delete . You can see an example at: http://www.grocerycr...k_escape_delete
[/quote]

Thanks!

This is my update code:


function gestioneimmagini(){
$info_menu['corrente'] = 3;

//Carico la libreria CRUD
$this->load->library('grocery_CRUD');
$crud = new grocery_CRUD();


$crud->set_table('immagini');
$crud->required_fields('immagine');
$crud->set_relation('id','cani','nome');
$crud->set_field_upload('immagine','assets/uploads/files');
$crud->callback_escape_delete(array($this,'cancella_riga'));

$output = $crud->render();


$this->load->view('admin/header',$info_menu);
$this->load->view('admin/gestione_razze',$output);
$this->load->view('admin/footer');

}

public function cancella_riga($primary_key){

}


in my table i have a primary_key formed by two attribute, how can i handle it now?
I need to create a query like

DELETE FROM immagini WHERE id='$id' AND name='$nome'

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

Posted 16 February 2012 - 22:22 PM

If you have the id why to have the name? A primary key is unique always so you will not have any problem with a simple callback_escape_delete

christian1988
  • profile picture
  • Member

Posted 17 February 2012 - 13:59 PM

[quote name='web-johnny' timestamp='1329430923' post='531']
If you have the id why to have the name? A primary key is unique always so you will not have any problem with a simple callback_escape_delete
[/quote]

i change the logic of my DB, now i don't need the callback function :)