Hi, thanks for response!
So picture is:
Let's say i have two tables - contractors and objects
Relation:
objects - id, street,...., contractor_id
contractors - id, name and so on.
I want implement adding, editing two table in the same time on one page. For that i get main table "objects" ($crud->set_table("objects")) and for contractors data i get them in callback column, callback fields and so on.
So:
Just for example we will work with one field from contractors - name
First of all add custom field "contractor_name" to $crud->fields(....,'contractor_name')
Then create callback_field for this field like $crud->callback_field('contractor_name',array($this,'_field_callback_name'))
And for display name - $crud->display_as('contractor_name', lang('name'))
In callback_field i just get value of field name from contractors table like:
public function _field_callback_name($value = null){
if($obj = $this->session->userdata('contractor')){ // here we get contractor object from session
$value = $obj->name;
}
return '<input type="text" maxlength="50" value="'.$value.'" name="name" style="width:462px">'; //for edit,insert state
// or
return $value; // for read state
}
I have two different callbacks for read and edit/insert state - i don't need input field in read state
And in controller i do something like this:
if(in_array($state,array('edit','update','read'))){
$primary_key = $state_info->primary_key;
$cur_contractor = $this->db->get_where('objects',array('id'=>$primary_key))->row()->contractor_id;
($obj = $this->db->get_where('contractors',array('id'=>$cur_contractor))->row()) == false ? show_404(): "'';
$this->session->set_userdata('contractor',$obj);
}
Here i get contractor object from contractors by contractor_id which is in object row and save to the session
Finally in callbacks before insert or update object i get from post array values about contractor fields and save them or update
So all works perfect in edit insert list state, but in read state all values presents but shows warnings that i mention in the begin of this post
What i am doing wrong? Can you help me?
tips and advices will come in handy! Thanks!
P.S. OFFTOPIC: I'm just thinking, what if I parse url string to find read state and return from callback_field in edit/insert - input field and in read just value. Then i no need two callbacks for one field in different states any more. How do you think, it's a good solution? just advise me plz:)