Hi I have been working all this week on this project that I'm helping my son with for his school project, the project is a PHP login script using the MVC design everything runs but I keep getting the following Warning: Trying to access array offset on value of type null in C:\wamp64\www\mvcloginregister\app\libraries\Core.php on line 18, line 18 is the following code:
// Look in BLL for first value
18 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]);
}
I think the issue is in the following function
public function getUrl(){
if(isset($_GET['url'])){
$url = rtrim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
}
I have reviewed all recommended answer related to this issue on this site and I'm unable to fix this issue I also found a post on google with the same issue but the person who fixed the issue did not post the solution which I think is rude and unprofessional. Please help I'm very new to this php language and the MVC design.
Today I had the same problem and also couldn't find any solution around the web. Finally I've solved it by myself: added the $url variable to the condition inside the "if" statement. this checks not only if the file exists but also if $url isn't null - like so:
$url = $this->getUrl();
if( $url && file_exists('../app/controllers/' . ucwords($url[0]). '.php') ){
$this->currentController = ucwords($url[0]);
unset($url[0]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.