CodeIgniter Forums
[solved]Concept of CI - Get DB results from Controller/Model and send to View. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [solved]Concept of CI - Get DB results from Controller/Model and send to View. (/showthread.php?tid=49354)



[solved]Concept of CI - Get DB results from Controller/Model and send to View. - El Forum - 02-16-2012

[eluser]Asshai[/eluser]
Hello,

This is how I take data from DB to my view. I do it inside the view, directly, showing the user name who's logged
in his profile.

Code:
// This code is part of a View
<div id="info_name_profile">
&lt;?php
  $login = $_SESSION['username'];
  $query = $this->db->query("SELECT * FROM USERS WHERE login = '$login';");

  $row = $query->row();
    
  echo $row->name;
?&gt;
</div>


...but, I'm searching how to do this but from a Controller/Model and send it to the VIEW? another way to do this? a standard CI way?

Any tip would be appreciated.

Ty.

***********UPDATE, solved. I'm a noob:

I've solved this question looking again at the video tutorial: http://codeigniter.com/tutorials/watch/blog/

In my Model there is a function where i take the data from DB. Then, in the Controller I got the result of that DB operation and send it to my view through:
Code:
$data['nameLogged'] = $res->name;

//And then to the view:
$this->load->view('template', $data);

//In the view, just echo the var :
&lt;?php echo $nameLogged; ?&gt;