1

I'm new at code igniter and I'm trying to figure out how to utilize 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?

1
  • foreach ($data['rows'] as $r){ Commented Jun 3, 2011 at 15:57

1 Answer 1

2

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) { ... }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.