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

#1
[eluser]furyan[/eluser]
Hi,

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,

#2
[eluser]m4rw3r[/eluser]
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.

Example:
Code:
// 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;

#3
[eluser]furyan[/eluser]
Thx, guess I shouldve read the documentation more thoroughly!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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