[eluser]Unknown[/eluser]
Hi,
I am new to CI and am currently trying to pass my query from my model to my controller and then into my view but I think I am getting confused as to what is an object etc.
My Model:
function get_band($id)
{
$this->db->where('id', $id);
$query = $this->db->get('bands');
if ($query->num_rows() > 0)
{
return $query;
}
}
My Controller:
function admin_edit_form($id)
{
$this->load->model('form_model');
$data['query'] = $this->form_model->get_band($id);
$data['base'] = $this->base;
$data['css'] = $this->css;
$data['title'] = "Results";
$this->load->view('admin_edit_view' , $data);
}
My View:
foreach ($query->result_array() as $row):
echo $row['myfieldname'];
endforeach;
Now how would I do this so that the foreach was done in the controller. Would it be a foreach loop as above and if so how would I assign each fieldname to the $data object. Then how would I reference it in the view, $this->query->myfieldname or $this->data->myfieldname.
I tried to dump_var(data) but got nothing.
I think the main problem is that I haven't really got my head round models and obects so I need to do some more reading.
Thanks