質問

First of all this post is not about form validations (javascript), but validations with respect to the database constraints..

When I add data through the add form, there are some cases which the database will not update due to database constraints I have initialized when making the database (such as duplicating primary key).. In such cases grocery crud add form will not display any error. but just kept displaying the ajax loader image.

When I edit data through the edit form, there are some cases which the database will not update due to database constraints I have initialized when making the database (such as foreign key on update constraints).. In such cases grocery crud add form will not display any error. but just kept displaying the ajax loader image.

When I try to delete a record from grocery crud table, there are some cases which the database will not let delete that record due to database constraints I have initialized when making the database (such as foreign key on delete constraints).. In such cases grocery crud will not display any error and do nothing.

In the above mentioned cases how can we display errors? is there any built in function for that in grocery crud? else how can we implement? (But when a record is inserted/edited/deleted successfully, grocery crud will display the successful msg)

This is important, because else user will think database did not update due to our coding bugs

役に立ちましたか?

解決

You can use callback before delete.

$crud->callback_before_delete(array($this,'cek_before_delete'));
$crud->set_lang_string('delete_error_message', 'This data cannot be deleted, because there are still a constrain data, please delete that constrain data first.');


function cek_before_delete($primary_key) {
    $this->db->db_debug = false;
    $this->db->trans_begin();
    $this->db->where('id', $primary_key);
    $this->db->delete('table_name');
    $num_rows = $this->db->affected_rows();
    $this->db->trans_rollback();
    if ($num_rows > 0) {
        return TRUE;
    } else {
        return FALSE;
    }
}

Then you can also do the same for callback before edit with $crud->callback_before_update.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top