CodeIgniter Forums
How to move data out of a model and into a controller - 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: How to move data out of a model and into a controller (/showthread.php?tid=50009)



How to move data out of a model and into a controller - El Forum - 03-10-2012

[eluser]Unknown[/eluser]
I am new to CodeIgniter but so far am excited to use the framework more.

I have a model which is called getUsers shown as follows:

Code:
function getUsers(){
        $query = $this->db->query("SELECT * FROM users");
}

This will return fields like user_id, username,activation, expiration. This to my understanding will be returned into result()

How do I take that data and bring it over to a controller function which will then take that data and put it in a table?

Any help understanding how this would work would be well appreciated. Further after that I will probably need help moving that into a view and getting the table formatted.


How to move data out of a model and into a controller - El Forum - 03-10-2012

[eluser]InsiteFX[/eluser]
Code:
function getUsers()
{
    $query = $this->db->query("SELECT * FROM users");
}

function get_user()
{
    $query = $this->db->get('users');

    if ($query->num_rows() > 0)
    {
        return $query->row_array();
    }

    return FALSE;
}

// Controller
function index()
{
    $data = array();

    $data['users'] = $this->model_name->get_user();
}