⚠ 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

[solved] How to show message if delete not success?



jinbatsu
  • profile picture
  • Member

Posted 18 December 2013 - 06:00 AM

Hello,

 

If data row is not deleted, it doesn't show any text message.

How can I display it?

 

EDIT:

Should I use callback_after_delete?

And check if the data is still exist?

Is there a way to show the error message?

 

 

Thank You


jinbatsu
  • profile picture
  • Member

Posted 14 January 2014 - 17:31 PM

I can do this with:

$crud->set_lang_string('delete_error_message', 'My Own Error Message Here!');
$crud->callback_before_delete(array($this,'cek_before_delete'));

	function cek_before_delete($primary_key) {
		$this->db->db_debug = false; // IMPORTANT! (to make temporary disable debug)
		$this->db->trans_begin();
		$this->db->where('id', $primary_key);
		$this->db->delete('your_table');
		$num_rows = $this->db->affected_rows();
		$this->db->trans_rollback();
		if ($num_rows > 0) {
			return TRUE;
		} else {
			return FALSE;
		}
	}