⚠ 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

Removing add or edit fields for inserting or updating data



carmad94
  • profile picture
  • Member

Posted 18 August 2014 - 08:52 AM

function placehistory()
{
    $crud = new Grocery_CRUD();
	$crud->set_table('place_history');
	$crud->columns('province','municipality','barangay','land_area','population','year');
	$crud->set_relation('place_id','place','{province} {municipality} {barangay}');
	$crud->callback_column('province',array($this,'_callback_view_province'))
	     ->callback_column('municipality',array($this,'_callback_view_municipality'))
	     ->callback_column('barangay',array($this,'_callback_view_barangay'));
	$crud->fields('place_id' ,'province','municipality','barangay','land_area','population','year');
	$crud->field_type('place_id','invisible');
	$crud->callback_before_insert(array($this,'_callback_placeID'));
	$crud->callback_field('province', array($this, '_callback_province'));
	$this->dependent_dropdown_place($crud); //dependent dropdowns for province, municipality, and barangay
}

Place_id is a primary key and is also a foreign key in the main table. I have displayed all columns -barangay, municipality, and province - from the table which place_id is the pk. I have successfully "join" the 2 tables for viewing purposes using callback columns. However I cannot insert or update data successfully. There is also no either success or error messages or debugging messages from firebug so I'm having a hard time identifying and fixing the problem. Can anyone help me? 

 

Above is my controller code. Below is my callback code before insert:

function _callback_placeID($post_array, $primarykey)
{
	$prov = $this->input->post('province');
	$mun = $this->input->post('municipality');
	$bar = $this->input->post('barangay');
	$post_array['place_id']=$this->shared_model->find_place_id($prov, $mun, $bar);

	return $post_array;
}

Thank you very much in advance for your help  :)

 


carmad94
  • profile picture
  • Member

Posted 19 August 2014 - 07:51 AM

Finally... I have found a solution to my problem. I just added something in my callback function

function _callback_place_id($post_array){
$mun= null;
	$bar= null;
	$prov = $post_array['province'];
	echo $prov;
	if(!empty($post_array['municipality']))
		$mun = $post_array['municipality'];
	if(!empty($post_array['barangay']))
		$bar = $post_array['barangay'];
	$post_array['place_id']=$this->shared_model->find_place_id($prov, $mun, $bar);

	unset($post_array['province']);
	unset($post_array['municipality']);
	unset($post_array['barangay']);
	return $post_array;
}

May this helps who have a problem similar to mine  :)