⚠ 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

how to get primary key value in add page



kdm
  • profile picture
  • Member

Posted 23 January 2013 - 06:29 AM

hi all,

i have used add_action() in list state.
when user clicks on that link, the primary key value is passed in url.
how can i get that primary key value in my callback_insert()...

if anyone has solution,please reply..

davidoster
  • profile picture
  • Member

Posted 23 January 2013 - 11:21 AM

check here: http://www.grocerycrud.com/documentation/options_functions/add_action
the callback function can be structured in a way that returns the primary key [b]AND [/b]the row id!!!

[color=#000000][b]function[/b][/color] just_a_test[color=#66CC66]([/color][color=#0000FF]$primary_key[/color] , [color=#0000FF]$row[/color][color=#66CC66])[/color]

davidoster
  • profile picture
  • Member

Posted 23 January 2013 - 11:28 AM

Oooops! Sorry didn't see you were referring to the the callback_insert!
I assume that on the $post_array there is also the primary_key value you are looking for.
I don't know your db structure but what ever you name it, e.g. name, city etc!!!

BUT if you primary_key is [b]AUTO generated [/b]for example it is an id that is auto incremented then you will not get until after the insert updates on the database.
Remember callback_insert takes over [b]BEFORE [/b]true update happens on the db!

kdm
  • profile picture
  • Member

Posted 23 January 2013 - 11:40 AM

ya its done,

thanks david

jhonroy
  • profile picture
  • Member

Posted 10 June 2016 - 09:05 AM

this is work to get primary key, if you want to make some row not editable when some field after updating.

use this..

$state_code = $crud->getState();
$state_info = $crud->getStateInfo();
			
if($state_code == 'edit') 
{
	$primary_key = $state_info->primary_key;
							
	$this->db->select('fieldX');
	$this->db->where('id_field', $primary_key);
	$q = $this->db->get('table_name');
	$data = $q->result_array();
		
	if(!empty($data[0]['fieldX']))	
	{
	 
		$crud->field_type('field1', 'readonly');	
		$crud->field_type('field2', 'readonly');	
        }
}