Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 829
Andrew Font Avatar asked Feb 07 '26 01:02

Andrew Font


2 Answers

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

like image 200
James McDonnell Avatar answered Feb 08 '26 15:02

James McDonnell


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

like image 29
coryj Avatar answered Feb 08 '26 14:02

coryj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!