⚠ 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

callback_after_insert not working



hasnain
  • profile picture
  • Member

Posted 25 January 2016 - 05:41 AM

I am trying to add data in 2 tables. In the first table there are only 3 columns "Cheque start date","No of cheque" and "Amount"

 and in the 2nd table i want to insert 'cheque_date','amount','pay_to' and "created_on" but in the 2nd table i want to insert these data "No of cheque" times, and 'cheque_date' will increase +1 month for each cheque for this i have written this code:

 

public function bulk_cheque(){
        $crud = new grocery_CRUD();

        $crud -> set_theme('datatables');
        $crud -> set_table('bulk_cheques');

         $crud -> add_fields('cheque_start_date', 'no_of_cheque','amount');
         $crud -> callback_after_insert(array($this, 'create_all_cheques'));
         $output = $crud -> render();

        $this -> _example_output($output);
    }
    public function create_all_cheques($post_array, $primary_key){
        $date=$post_array['cheque_start_date'];
        $pay_to=$this->db->get('config')->row_array();
        for($i=0;$i>$post_array['no_of_cheque'];$i++) {
            $date=date('Y-m-d', strtotime("+1 months", strtotime($date)));
            $data_array=array(
            'cheque_date'=>$date,
            'amount'=>$post_array['amount'],
            'pay_to'=>$pay_to['pay_to'],
            "created_on" => date('Y-m-d H:i:s')
            );
            var_dump($data_array);
        $this->db->insert('cheques',$data_array);
        
        }
        

        return true;
    }


tomomiha
  • profile picture
  • Member

Posted 09 February 2017 - 17:04 PM

I solved this issue by using only insert_callback, where you can manually save your

fields and after successfully saving it - you can do whatever you want to happen after saving :)

Or maybe try to call other method from within that callback, eg. $this->method($params);