⚠ 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

is possible Callback_After_Insert Return Var value instead true or false?



firdausibnu

firdausibnu
  • profile picture
  • Member

Posted 13 July 2018 - 10:48 AM

assume callback_after_insert like this :        

$crud->callback_after_insert(array($this, 'load_data'));

and the function like this :

 

    

function load_data($post_array) {
        $success = true;

        try {

            $DOCUMENT_ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);

            $reader = ReaderFactory::create(Type::XLSX); //set Type file xlsx
            $reader->open($file_path); //open the file
        
            echo "<pre>";
            $i = 0;
            $j = 0;

            $this->db->trans_begin();

            foreach ($reader->getSheetIterator() as $sheet) {

                //Rows iterator

                foreach ($sheet->getRowIterator() as $row) {

                    if ($i > 0) {
                
                        $upload_row_insert = array(
                            "psdn_psd_id" => $post_array['upd_remarks'],
                            "psdn_item_no" => $row[0],
                            "psdn_nd1" => $row[1],
                            "psdn_nd2" => $row[2],
                            "psdn_cstatus" => "Draft",
                            "psdn_crole" => "Inputter"
                        );

                        $query = $this->db->where('( (psdn_nd1 = "' . $upload_row_insert['psdn_nd1'] . '" and psdn_nd2 = "' . $upload_row_insert['psdn_nd2'] . '") or  (psdn_nd1="' . $upload_row_insert['psdn_nd2'] . '" and psdn_nd2= "' . $upload_row_insert['psdn_nd1'] . '")) and  psdn_psd_id = "' . $post_array['upd_remarks'] . '"')
                                ->get('pob_starclick_details_nd');

                        if ($query->num_rows() == 0) {
                            $this->db->insert('pob_starclick_details_nd', $upload_row_insert);
                            $j++;
                        } else {

                            $this->db->trans_rollback();
                            $rw = $j + 1;
                            global $nd_message;
                            $nd_message = 'Duplicated Data on Row ' . $rw;
                            $success = false;
                            $reader->close();

                            return $success;
                        }
                    }
                    ++$i;
                }
            }
            $reader->close();
        } catch (Exception $e) {
            $data = array(
                'upd_status' => 'error',
                'upd_message' => $e->getMessage()
            );
            $this->db->where('upd_id', $primary_key);
            $this->db->update('file_upload_nd', $data);
            $success = false;
        }

        return $success;
    }

In this case, if the data has duplicate row on database will proceduce error message on $nd_message variable.

 

and set custom error message with 

    $crud->set_lang_string('insert_error', $nd_message);

but value of $nd_message not appear, so grocery reproduce default message error on insert "An error has occurred on insert." and make user confuse ~.

 

any idea for custom error message? 

i tried to set message with global variable but useless, and this make me crazy.

 

Please Help, Thanks Guys.