Welcome Guest, Not a member yet? Register   Sign In
Passing and accessing values within data between controller and view
#1

The tutorial has the following code to retrieve an array result from the database

       $data['news'] = $this->news_model->get_news();

And in the view the array result is accessed with

<?php foreach ($news as $news_item): ?>

That is to say: The 'news' inside the $data array can be accessed as the variable: $news when you pass $data to the controller

For some reason I am unable to do this with my own controller/view

               // retrieve a result set from my model. Tracing thru eclipse shows that results
              // are returned from the database
$data['accounts'] = $this->accounts_model->get_accounts();
             
              // as long as I do this in my controller I can access the result set
foreach ($data['accounts'] as $row) {
echo $row['account'] . '</br>';
echo $row['ledger'] . '</br>';
echo $row['description'] . '</br>';
}

              //But this does not work
foreach ($accounts as $row) {
echo $row['account'] . '</br>';
echo $row['ledger'] . '</br>';
echo $row['description'] . '</br>';
}

And referring to $accounts in the view does not work either. In both cases $accounts is undefined.
Reply


Messages In This Thread
Passing and accessing values within data between controller and view - by Shawn - 04-11-2015, 07:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB