Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
注意:试图访问第15行H:\xampp\htdocs\ecommerce\app\libraries\Core.php中null类型值的数组偏移量_Php_Notice - Fatal编程技术网

注意:试图访问第15行H:\xampp\htdocs\ecommerce\app\libraries\Core.php中null类型值的数组偏移量

注意:试图访问第15行H:\xampp\htdocs\ecommerce\app\libraries\Core.php中null类型值的数组偏移量,php,notice,Php,Notice,我也遇到了这个问题 <?php /* * App Core Class * Creates URL & loads core controller * URL FORMAT - /controller/method/params */ class Core { protected $currentController = 'Pages'; protected $currentMethod = 'index'; protecte

我也遇到了这个问题

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



public function __construct(){
      //print_r($this->getUrl());
      $url = $this->getUrl();
      // Look in controllers 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;
      }
    }
  } 
  
在这里,您可能需要添加
!空($url[0])&&

文件\u存在之前
这肯定会使您的问题得到解决

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]);
  }`