03-17-2016, 04:08 PM
Hello!
I am fairly new to Codeigniter and have come up against something that is alluding me. Perhaps it's the time of day, or that my code isn't as elegant as it could be.
Summary of problem.
I have a view that has a dependent dynamic dropdown. When you select from first dropdown, a java function makes an ajax call to a controller function which uses a model to pull options for the second dropdown from a DB.
When I SAVE a DB record to reflect the chosen options it saves the "value" of the <option> tag. When I LOAD that record I get the value back, but I actually need the NAME, not the value.
So, I'm trying to include a translator that will catch the data at the controller as it comes from the model to the view, translate the value into the name and then include the name in the object being passed to the view.
What I need to do is access one specific element of the object. I'd rather not create an array, parse the object into the array, and then use the array element to pass back into the model to retrieve the name.
Controller:
MODEL:
Any thoughts and/or suggestions?
I am fairly new to Codeigniter and have come up against something that is alluding me. Perhaps it's the time of day, or that my code isn't as elegant as it could be.
Summary of problem.
I have a view that has a dependent dynamic dropdown. When you select from first dropdown, a java function makes an ajax call to a controller function which uses a model to pull options for the second dropdown from a DB.
When I SAVE a DB record to reflect the chosen options it saves the "value" of the <option> tag. When I LOAD that record I get the value back, but I actually need the NAME, not the value.
So, I'm trying to include a translator that will catch the data at the controller as it comes from the model to the view, translate the value into the name and then include the name in the object being passed to the view.
What I need to do is access one specific element of the object. I'd rather not create an array, parse the object into the array, and then use the array element to pass back into the model to retrieve the name.
Controller:
Code:
function loadRMA(){ //Function to load the RMA data from the DB
$data['rmaRecordMode'] = "view"; //Just view the record data
$data['rmaNumberToGet'] = $this->input->post('GetThisRmaNum');
$this->load->model('rma_model');
$data['assemblies'] = $this->rma_model->getAssembly(); //Get Assemblies from DB
$data['rmaData'] = $this->rma_model->getRMAData(); //Get specific RMA data
//NEED TO GET ELEMENTn OF rmaData and pass it to $this->rma_model->translateDropDown(n, rmaData value n)
$this->load->view('includes/rma_header', $data);
$this->load->view('rma_home', $data);
$this->load->view('includes/footer');
}
Code:
public function translateDropDown($type, $id){ //Function to translate the dropdown saved index value to its name value
if($type == 'category'){
$fieldList='category';
$table='fx_categorycomponentsymptom';
$fieldName='id';
$orderByField='category';
}else if($type == 'component'){
$fieldList='component';
$table='fx_categorycomponentsymptom';
$fieldName='id';
$orderByField='component';
}else if($type == 'symptom'){
$fieldList='symptom';
$table='fx_categorycomponentsymptom';
$fieldName='id';
$orderByField='symptom';
}
$this->db->select($fieldList);
$this->db->from($table);
$this->db->where($fieldName, $id);
$this->db->order_by($orderByField, 'asc');
$query=$this->db->get();
return $query;
}//end translateDropDown
public function getRMAData(){ //FUNCTION TO PULL RMA DATA FROM SB TABLE
$this->db->select('*');
$this->db->from('rma');
$this->db->where('rmaNumber', $this->input->post('GetThisRmaNum'));
$query = $this->db->get();
return $query->result();
}
Any thoughts and/or suggestions?