Welcome Guest, Not a member yet? Register   Sign In
fill dropdown using ignited record
#1

[eluser]arjo[/eluser]
I want to fill a dropdown selectbox using ignited record but I get the following error:

Message: Object of class IR_record could not be converted to string

Here is my code:

Code:
//controller
$this->load->model('MDocumenttypes','documenttypes');
$data['documenttype'] = $this->documenttypes->getDropDown();
$this->load->vars($data);

//model
function getDropDown() {
  $this->select('documenttype_ID, name');
  $recs = $this->find_all();
  return $recs;
}

//view
<p><label for='documenttype'>Documenttype</label><br />
&lt;?=form_dropdown('documenttype_ID',$documenttypes,$document->documenttype_ID);?&gt;
</p>

I tried to convert the object to an array but I got stuck here:

Code:
function getDropDown() {
  $this->select('documenttype_ID, name');
  $recs = $this->find_all();
  $data = $recs->get_data();
  
  //debuggin loop to show content of array  
  foreach($data as $column => $value)
  {
    echo "$column => $value\n";
  }
  exit;
  
  return $data;
}
Unfortunately get_data() only works if you populate $recs using $this->get().
And this returns just 1 record Sad

If I loop through the array using the find_all() method (like above) it returns the following error:

Fatal error: Call to a member function get_data() on a non-object

Does anyone know how what I should do (beside going to the beach bc the weather is too good to do stuff like this now Wink

greetz Arjo
#2

[eluser]arjo[/eluser]
Thanks to my college Martijn, here's the answer:

Code:
function getDropDown() {
  $this->select('documenttype_ID, name');
  // get all records
  $records = $this->find_all();
  // empty array
  $data = array();
  
  // loop all records
  foreach($records as $record)
  {
    // fill data array
    $data[$record->documenttype_ID] = $record->name;
  }

  return $data;
}




Theme © iAndrew 2016 - Forum software by © MyBB