how to get primary key value in add page
- Single Page
Posted 23 January 2013 - 06:29 AM
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..
Posted 23 January 2013 - 11:21 AM
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]
Posted 23 January 2013 - 11:28 AM
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!
Posted 23 January 2013 - 11:40 AM
thanks david
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'); } }