php - Codeigniter: How do I display the value returned by a model function on a view textbox during data entry -
this question based on following tables.
procedures - id | procedure_name |cost visits - id | visit_date | patient_id | notes | staff_id visits_procedures - id | visit_id | procedure_id | quantity payments - id | visit_id | payment_date | amount | payment_method_id | transanction_id | payment_status_id
the payments table records total amount paid during visit based on number of procedures performed. visits_procedures table tracks number of procedures performed during visit. trying populate amount textbox value returned get_visit_amount()
function in model when creating new payment. getting error 'undefined variable: amount'. appreciate ideas on how make work. below code snippets.
payment model
public function get_visit_amount(){ $this->db->select_max('id'); $result= $this->db->get('visits')->row_array(); $answer = $result['id']; $this->db->select('sum(procedures.cost * visits_procedures.quantity) amount, visits_procedures.visit_id'); $this->db->from('procedures'); $this->db->join('visits_procedures', 'visits_procedures.procedure_id = procedures.id', 'left'); $this->db->where('visits_procedures.visit_id', $answer); $query = $this->db->get()->row_array(); return $query['amount']; }
payments controller
public function create() { if ($this->input->post('payment_method_id')) { $data['visit_id'] = $this->visit->get_latest_id(); $data['payment_date'] = date('y-m-d h:i:s'); $data['amount'] = $this->payment->get_visit_amount(); $data['payment_method_id'] = $this->input->post('payment_method_id'); $data['transaction_id'] = $this->input->post('transaction_id'); $data['payment_status_id'] = $this->input->post('payment_status_id'); //set flash data $this->session->set_flashdata('display_amount', $amount); redirect('/admin/payments/create'); $this->payment->insert($data); redirect('/admin/payments', 'refresh'); } . .// code load page . }
payments_create view
<form class="form-horizontal" role="form" method="post" action="<?=base_url()?>admin/payments/create"> . .//code . <div class="form-group"> <label class="col-md-3 col-xs-12 control-label">amount</label> <div class="col-md-6 col-xs-12"> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-pencil"></span></span> <input type="text" class="form-control" id="amount" name="amount" value="<?php echo $this->session->flashdata('display_amount'); ?>"/> </div> </div> </div> . .//code . </form>
use flashdata store information.
$this->session->set_flashdata('item', 'value');
and retrieve in new page with
$this->session->flashdata('item');
wiki
Comments
Post a Comment