0

Can anyone help me with this error?

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\dev1\freelance\app\core\Controller.php on line 245

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\dev1\freelance\app\core\Controller.php on line 246

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\dev1\freelance\app\core\Controller.php on line 250

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\dev1\freelance\app\core\Controller.php on line 251

 * This is the method from where you can pass data to the Header view
 *
 * @return string
 */
private function getHeader()
{
    $data = [
        'languages_list'    => $this->languages,
        'language'          => $this->language
    ];
    
    $data['url'] = $this->url[0];
    
    /*Use User Library*/
    $user = $this->library('User');
    $data['user'] = $user->data();
    $data['user_isloggedin'] = $user->isLoggedIn();
    
    /*Use Client Model*/
    $clientModel = $this->model('Client');
    $data['client_unread_messages'] = $clientModel->unread_messages($data['user']['userid']);
    $data['client_unread_notifications'] = $clientModel->unread_notifications($data['user']['userid']);
    
    /*Use Freelancer Model*/
    $freelancerModel = $this->model('Freelancer');
    $data['freelancer_unread_messages'] = $freelancerModel->unread_messages($data['user']['userid']);
    $data['freelancer_unread_notifications'] = $freelancerModel->unread_notifications($data['user']['userid']);

    return $this->view->render($data, 'shared/header');
}

Image of code with line nrs

  • Assuming that the code you posted is from the file C:\xampp\htdocs\dev1\freelance\app\core\Controller.php, I think it could be helpful if you highlighted the lines 245, 246, 250 and 251. – Javito Sep 13 '22 at 05:35
  • 1
    I attached an image with the line nrs – Christo Lochenberg Sep 13 '22 at 05:35
  • Sorry I didn't notice before. The error is ocurring every time you try to access $data['user']['userid'] and by the message of the error, it looks like $data['user'] is null. The problem is most likely in line 240, $user->data() is returning null. – Javito Sep 13 '22 at 05:42
  • Any idea on how i fix this? – Christo Lochenberg Sep 13 '22 at 05:48
  • I can tell you where would I start. I would go inside the data() function of the $user object and debug it. There is probably some sort of mistake or error inside that function that causes it to return null. – Javito Sep 13 '22 at 05:54
  • Most likely `$data['user']` returns null, so your access to `userid` returns the mentioned warnings. Are you meaning `$user["userid"]` here? From the code it seems incorrect, that `$data["user"]` is set to `$user->data()` but threaded as the user object itself later. (Would mean `$user->data()` would need to contain the user object again, doesn't seem right) – dognose Sep 13 '22 at 07:22

0 Answers0