Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

How to get data objects in controller

$
0
0
I'm really new to this so excuse my query on something that is probably fundamental but...

I have a controller that has the model in the constructor, I have created a method in the model which grabs a record from the database.
I call it in my controller like so:

$data['user'] = $this->jobseekers_model->getUser($userId);

Now I have checked and it is returning an array, I can see it using print_r but I can't seem to figure out how to get an array element, I am trying to set a session var using:

$newdata = array(
        'username'  => $user['username'],
        'email'     => $user['email'],
        'logged_in' => TRUE
        );

 but then I get the error:
Message: Undefined variable: user

can anyone please advise?
Do I need to loop through the array first an assign each array element to a new array? Surely not?

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>