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

6
  • 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. Commented Sep 13, 2022 at 5:35
  • 1
    I attached an image with the line nrs Commented Sep 13, 2022 at 5: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. Commented Sep 13, 2022 at 5:42
  • Any idea on how i fix this? Commented Sep 13, 2022 at 5: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. Commented Sep 13, 2022 at 5:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.