I was use callback_before_insert in "A" controller and its working. But after i copied "A" controller to "B" controller, is not working at all. Here's the code :
function tests_display(){
$crud = new grocery_CRUD();
$crud->set_model('tests_crudmodel');
$crud->set_theme('flexigrid');
$crud->set_table('tests');
$crud->set_subject('Soal Ujian');
$crud->columns('date','information','class_id','question_id','percentage','total_qty','duration','maximum_value','maximum_skip','start');
$crud->display_as('date','Tanggal Pembuatan');
$crud->display_as('information','Keterangan');
$crud->display_as('class_id','Untuk Kelas');
$crud->display_as('question_id','Sumber Soal');
$crud->display_as('percentage','Komposisi Soal');
$crud->display_as('total_qty','Total Soal');
$crud->display_as('duration','Durasi Soal (menit)');
$crud->display_as('maximum_value','Nilai Maksimum');
$crud->display_as('maximum_skip','Total Skip');
$crud->display_as('start','Publish');
$crud->fields('information','class_id','question_id','percentage','total_qty','duration','maximum_value','maximum_skip','start');
$crud->required_fields('information','class_id','question_id','percentage','total_qty','duration','maximum_value');
$dataclass = $this->classes->lists_array();
$dataquestions = $this->classes->questions_lists_array();
$datapercentage = array(100=>'100%',90=>'90%',80=>'80%',70=>'70%',60=>'60%',50=>'50%',40=>'40%',30=>'30%',20=>'20%',10=>'10%',0=>'0%');
$crud->change_field_type('class_id','multiselect',$dataclass);
$crud->change_field_type('question_id','multiselect',$dataquestions);
$crud->change_field_type('percentage','multiselect',$datapercentage);
$crud->change_field_type('total_qty','integer');
$crud->change_field_type('duration','integer');
$crud->change_field_type('maximum_value','integer');
$crud->change_field_type('maximum_skip','integer');
$crud->change_field_type('start','true_false');
$crud->callback_before_insert(array($this, 'insert_data'));
$crud->callback_add_field('start',array($this,'callback_edit_start'));
$crud->callback_edit_field('start',array($this,'callback_edit_start'));
$crud->set_rules('question_id', 'Sumber Soal','callback_simpan_sumber_soal');
$crud->set_rules('percentage', 'Prosentase','callback_percentage_check');
$output = $crud->render();
$this->_crud_output($output);
}
function insert_data($post_array)
{
$rs = $this->school_years->get_active_school_year();
$post_array['school_year_id'] = $rs[0]['id'];
$post_array['date'] = date('Y-m-d');
$post_array['time'] = date('H:i:s');
$post_array['ip'] = $_SERVER['REMOTE_ADDR'];
//echo var_dump($post_array);
return $post_array;
}
my temp solution is to embeed my callback_before_insert code into db_insert in my own model like these:
function db_insert($post_array)
{
$CI =& get_instance();
$CI->load->model('school_years_model','school_years');
$rs = $CI->school_years->get_active_school_year();
$post_array['school_year_id'] = $rs[0]['id'];
$post_array['date'] = date('Y-m-d');
$post_array['time'] = date('H:i:s');
$post_array['ip'] = $_SERVER['REMOTE_ADDR'];
$insert = $this->db->insert($this->table_name,$post_array);
if($insert)
{
return $this->db->insert_id();
}
return false;
}
Could anyone tell me, why it happens? Thanks for your kindly reply