如何解决表情:尝试在第15行的H:\ xampp \ htdocs \ ecommerce \ app \ libraries \ Core.php中访问类型为null的值的数组偏移量
<?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;
}
}
}
上面的代码包含如下错误:试图在第18行的H:\ xampp \ htdocs \ ecommerce \ app \ libraries \ Core.PHP中访问类型为null的值的数组偏移量
require_once'../app/controllers/'。 $ this-> currentController。 '.PHP';
这是一行。当我使用domain.com输入网站时,显示此错误;当我输入domian.com/post时,则没有问题
解决方法
我也遇到了这个问题。
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]);
}`
在这个地方也许你必须添加!empty($url[0])&&
在 file_exists
之前,这肯定是你的问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。