I’m trying to set profile div box in MY_Controller based on whether the user is logged in or not.
If I can do this in a controller
$data['name'] = $name;
.. then why does this give me “Fatal error: Cannot use object of type stdClass as array” ?
if($this->session->userdata('loggedInStatus') == "TRUE"){
$data['profileDivFirstName'] = $this->session->userdata('first_name');
$data['profileDivPicture'] = $this->session->userdata('picture');
$this->load->vars( $data );
}else{
$data['profileDivInfoFirstName'] = "Anonymous User";
$data['profileDivInfoPicture'] = "/assets/css/img/ico-unknown-user.gif";
$this->load->vars( $data );
}
You have already instantiated
$datawhich is an object. Since you’re in MY_Controller, it is likely you made it. The code you posted doesn’t show us much, but this:Won’t work if
$datais an object because an object expects you to use this format:That will (or should, anyway) work, but you should look over your code to make sure you’re not using that in something else, too.