CodeIgniter Forums
getData() -- please explain - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: getData() -- please explain (/showthread.php?tid=19309)



getData() -- please explain - El Forum - 06-03-2009

[eluser]JPrieto[/eluser]
Lately I have been reading the USER GUIDE
and following some of its examples
to learn and bother less user of this forum

in one of the "Hello World" tutorial

there is a code in the controller as follows:
Code:
<?php
    class Helloworld extends Controller
  {
        function index()
        {
            $this->load->model('helloworld_model');

            $data['result'] = $this->helloworld_model->getData();
            $data['page_title'] = "CI Hello World App!";

            $this->load->view('helloworld_view',$data);
        }
    }
?>

MY QUESTION IS....

Where can I find more info on the getData() tag?
I can't find it in the USER GUIDE.

Anyone knows where in the USER GUIDE I can read up on it?

and how does it differ from ...->get('table');


THANKS


getData() -- please explain - El Forum - 06-03-2009

[eluser]drewbee[/eluser]
That is a model. Models are used to manipulate data, regardless of the source (Think databases, files, but not limited too);

On your example above, there should be a model called 'helloworld_model' in the models folder, with a method called getData() which presumably returns a database query.

This is no different then the get('table') setup, and infact you will come to find models tend to be wrappers for active record, at least in the beginning.


getData() -- please explain - El Forum - 06-03-2009

[eluser]Dam1an[/eluser]
Whats the link for this tutorial in the user guide? Cause I can't remember coming accross it :-S

The getData is just a function in the helloworld model (or so it would appear from the above code)

Edit: Drewbee beat me... someone always beats me Sad


getData() -- please explain - El Forum - 06-03-2009

[eluser]JPrieto[/eluser]
wow -- now i really feel very dumb

you are so right -- it is not a tag .... it is the name of a function (see below)

well, I guess this experience is part of learning.

uhm ... you are very smart (just as I thought from the start)

Many Thanks


Code:
function getData()
        {
            /* Query the data table for every record and row */
            $query = $this->db->get('data');
            
            if ($query->num_rows() < 0)
            {
                show_error('Database is empty!');
            }
      else
      {
                return $query->result();
            }
        }