I'm new at code igniter and I'm trying to figure out how to utiliz开发者_C百科e data returned from my database. I have a simple query in the model:
function feed_get_all_trees(){
$query = $this->db->get('trees');
foreach ($query->result() as $row){
$data[] = $row;
}
return $data;
}
Then in the controller, I am building an XML Feed with the help of an XML plugin library I found, so I want to echo the data out in the controller rather than in a view. Normally, if I was using a view, I'd do this:
$this->load->model('Model_form','', TRUE);
$data['rows'] = $this->Model_form->feed_get_all_trees(); //gets the available groups for the dropdown
$this->load->view('view_name',$data);
}
But in order to construct my XML feed - I need to access data right here. If I try this:
foreach ($rows as $r){
$treeName = $r->tree_name;
$xml->startBranch('tree');
$xml->addNode('treeName',$treeName);
$xml->endBranch();
I get an error, because it doesn't know what $rows
is. How do I refer to data['rows']
here so I can access the data?
Not sure if I fully understand what you're trying to do as I've never used any XML plugin, but wouldn't you just do something like this to access the data?
$data['rows'] = $this->Model_form->feed_get_all_trees();
foreach($data['rows'] as $row) { ... }
精彩评论