у меня возникли проблемы с загрузкой индексной страницы, я получаю сообщение об ошибке при работе с MVC в php

#php #model-view-controller

#php #model-view-controller

Вопрос:

     <?php
  /*
   * App Core Class
   * Creates URL amp; loads core controller
   * URL FORMAT - /controller/method/params
   */
  class Core {
    protected $currentController = 'Pages';
    protected $currentMethod = 'index';
    protected $params = [];

    public function __construct(){
      $url = $this->getUrl();

      // Look in BLL for first value
      if(file_exists('../app/controllers/' . ucwords($url[0]). '.php')){
        // If exists, set as controller
        $this->currentController = ucwords($url[0]);
        // Unset 0 Index
        unset($url[0]);
      }

      // Require the controller
      require_once '../app/controllers/'. $this->currentController . '.php';

      // Instantiate controller class
      $this->currentController = new $this->currentController;

      // Check for second part of url
      if(isset($url[1])){
        // Check to see if method exists in controller
        if(method_exists($this->currentController, $url[1])){
          $this->currentMethod = $url[1];
          // Unset 1 index
          unset($url[1]);
        }
      }

      // Get params
      $this->params = $url ? array_values($url) : [];

      // Call a callback with array of params
      call_user_func_array([$this->currentController, $this->currentMethod], $this->params);
    }

    public function getUrl(){
      if(isset($_GET['url'])){
        $url = rtrim($_GET['url'], '/');
        $url = filter_var($url, FILTER_SANITIZE_URL);
        $url = explode('/', $url);
        return $url;
      }
    }
  }
  

Я получаю сообщение об ошибке ниже

Внимание: попытка получить доступ к смещению массива по значению типа null в C:xampphtdocsemsapplibrariesCore.php в строке 16 Представление не существует

у меня есть поиск, который пытался выяснить это, но ничего не проходит

Комментарии:

1. Это означает $url , что есть null . Что означает, что getURL() вернул значение null. Что, вероятно, означает if(isset($_GET['url'])){ , что возвращено false , и, следовательно, getURL() не выполнил свою return инструкцию. Если вы не указали ?url=something конец URL-адреса, который вы использовали для вызова представления, то именно поэтому это произойдет.

2. О да, спасибо за помощь

3. NP. Значит, это отвечает на вопрос / решает проблему?

4. да, это так, спасибо