I'm newbie for grocery crud. I have a simple database for accounting of insurance policies. In the main table (dogovor) I keep the insurance contract. This table is linked to another, that contains insurance policies under the contract (dogovor_persons). A contract can have multiple policies. How can I display on the edit form of an insurance contract list of related policies?
Now I can see a list of contracts (dogovor). I can get a list of policies with the selection the current contract. I can edit a contract using standard functions. How can I display a list of policies (polises_by_dogovor) in the edit form of the insurance contract (dogovor table)?
public function dogovor() { $crud = new grocery_CRUD(); $crud->set_table('dogovor'); $crud->set_subject('dogovor'); $crud->set_relation('country','countries','country'); $crud->set_relation('program','programs','name'); $crud->set_relation('agent','users','login'); // .....other standart items $crud->columns('id','created','Person','dateofbirth','country'); $crud->fields('id','Person','dateofbirth','program','tarif','country','created','edited_by'); //in this place I call the function to add the policy with the selection of an insurance contract $crud->add_action('add policie', 'http://www.grocerycrud.com/assets/uploads/general/smiley.png', 'calc/polises_by_dogovor'); $crud->callback_before_insert(array($this,'set_created_date'));//Ñтавим дату ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð¿ÐµÑ€ÐµÐ´ добавлением нового договора $output = $crud->render(); $this->_example_output($output); } public function polises_by_dogovor($did) { try{ $crud = new grocery_CRUD(); $crud->set_table('dogovor_persons'); $crud->required_fields('fio'); $crud->columns('born','passport_serie','passport_no'); $crud->where('did',$did); $crud->callback_field('did',array($this,'insert_dogovor_ID')); //set parent ID $output = $crud->render(); $this->_example_output($output); }catch(Exception $e){ show_error($e->getMessage().' --- '.$e->getTraceAsString()); } } function insert_dogovor_ID($value = '', $primary_key = null) //set parent ID { return '<input type="text" maxlength="11" value="'.$this->uri->segment(3).'" name="did" style="width:462px">'; }