Andrew Font
Andrew Font

Reputation: 1285

Undefined index error in codeigniter

Just for some background I am using codeigniter with the template sparks.

So in my controller i have the following function

public function information()
{     
$this->load->library('session');
$developer_id = $this->session->userdata('developer_id');
$this->load->model("Developer_model");
$information = $this->Developer_model->get_developer($developer_id);
$this->template->set('information', (array) $information); 
$this->template->build('dashboard/information'); 
}

In my view i am echoing out like so

<?php echo $information['email']; ?>

For some reason i am getting back "Message: Undefined index: email"

This my first question so hopefully i am not to unclear, but essentially i am getting $information from my database and trying to echo out the email which is just one thing in an array of items.

When i var_dump $information i get the following:

object(stdClass)#21 (2) { ["timestamp"]=> int(1353444880991) ["result"]=> object(stdClass)#22 (3) { ["email"]=> string(21) "[email protected]" ["api_key"]=> string(64) "de0f57acfc018882841b3255e89da11cb238160e84a66fe5b45bda8c51137c72" } } 

Thanks in advance for the help, only been working with codeigniter for 2 months prior to that i have literally done no coding besides some really minor html nonsense., so go easy on me =D

Upvotes: 3

Views: 6238

Answers (2)

coryj
coryj

Reputation: 1255

In your model return response->result; instead of response. And then you can use ... $information['email']; ...should work

Upvotes: 3

James McDonnell
James McDonnell

Reputation: 3710

If you look at your vardump, there is a second class "result" inside of your information class. Try $information["result"]["email"];

Upvotes: 5

Related Questions