• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving data and displaying it in a view


I have a function in my model to retrieve data, but how do I show this information in the view? I read its recommended to only load models in controllers, but how do I pass whole pieces of data from the controller to a view?

Im kinda new to frameworks, so forgive my noobness.

Thanks in advance,

Use the second parameter of the Loader::view() method, passing the data in an array with the key as the name and the value as the data to pass.

// controller:
$post = $this->post->find(); // fetch from your model

$this->load->view('post/display', array('post' => $post));

// view:
<h1>&lt;?php echo $post->title ?&gt;</h1>
&lt;!-- etc. --&gt;

Thx, guess I shouldve read the documentation more thoroughly!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.