Welcome Guest, Not a member yet? Register   Sign In
passing data from a controller to my view
#1

[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


Messages In This Thread
passing data from a controller to my view - by El Forum - 03-10-2009, 09:51 AM
passing data from a controller to my view - by El Forum - 03-10-2009, 10:02 AM
passing data from a controller to my view - by El Forum - 03-10-2009, 10:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB